diff options
author | Markus Heidelberg <markus.heidelberg@web.de> | 2014-12-29 14:27:55 +1100 |
---|---|---|
committer | Markus Heidelberg <markus.heidelberg@web.de> | 2014-12-29 14:27:55 +1100 |
commit | 95033e3837ac066c31853a176f1dd94422fa4838 (patch) | |
tree | 1e54604e7bc76e8981be4b1c694dee4fa5529b0d | |
parent | beb255f37f7c985561403ec57df995da336fe589 (diff) | |
download | scintilla-mirror-95033e3837ac066c31853a176f1dd94422fa4838.tar.gz |
S-Record lexer: correctly count the characters of an invalid short line
If the line only consisted of 3 digits (e.g. S12), then highlighting of
the third one (first digit of the "count" field) was dependent on the
content of the subsequent line. Now this digit is always highlighted as
valid "byte count", independent on its value, if there is no further
digit behind.
The function return value can be negative now.
-rw-r--r-- | lexers/LexHex.cxx | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/lexers/LexHex.cxx b/lexers/LexHex.cxx index ff4aec3a8..9b35732f6 100644 --- a/lexers/LexHex.cxx +++ b/lexers/LexHex.cxx @@ -154,23 +154,33 @@ static int GetSrecByteCount(unsigned int recStartPos, Accessor &styler) return val; } -// Count the number of digit pairs in this record from "address" field to end -// of line. Has to be equal to the "byte count" field value. +// Count the number of digit pairs for the "address", "data" and "checksum" +// fields in this record. Has to be equal to the "byte count" field value. +// If the record is too short, a negative count may be returned. static int CountSrecByteCount(unsigned int recStartPos, Accessor &styler) { + int cnt; unsigned int pos; - // start counting at "address" field - pos = recStartPos + 4; + pos = recStartPos; while (!IsNewline(styler.SafeGetCharAt(pos, '\n'))) { pos++; } - // divide by 2 because of digit pairs - // Round up if odd (digit pair incomplete), this way the byte count is - // considered to be valid if the checksum is incomplete. - return ((pos - (recStartPos + 4)) + 1) / 2; + // number of digits in this line minus number of digits of uncounted fields + cnt = static_cast<int>(pos - recStartPos) - 4; + + // Prepare round up if odd (digit pair incomplete), this way the byte + // count is considered to be valid if the checksum is incomplete. + if (cnt >= 0) { + cnt++; + } + + // digit pairs + cnt /= 2; + + return cnt; } // Get the size of the "address" field. |