aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarkus Heidelberg <markus.heidelberg@web.de>2014-12-29 14:27:55 +1100
committerMarkus Heidelberg <markus.heidelberg@web.de>2014-12-29 14:27:55 +1100
commit2d7a1e5afcf2d130973be607860b6d679b2d82ed (patch)
tree959a1bf06d17a82d8bd2a0543cfa1d73c4af5a15
parentd17f2ebdcbb13d59303ae3728fe969f3e3ef8ef8 (diff)
downloadscintilla-mirror-2d7a1e5afcf2d130973be607860b6d679b2d82ed.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.cxx26
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.