mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
syslog: fold the port parser's split conditions back together
The loop tested the digit range and the overflow bound with separate ifs, on the strength of a comment saying the joined form makes sdcc park a boolean in the bit area, and that an image carrying LACP and STP as well is one bit short of needing a third byte of it. Measured on this branch that is not what happens: the joined form links, the bit segment is unchanged at fourteen bits overall and nine in cmd_parser, and BANK2 comes out ten bytes smaller. The claim was about an image this branch does not build, and no branch currently carries LACP, STP and this parser at once, so there is nothing left to check it against. A justification nobody can verify, for a shape nobody would otherwise write, is worse than no comment at all. Behaviour is unchanged. The two forms agree on every input from 0 to 99999 and on the edges: empty, non digits, trailing junk, leading zeros, 65535 and 65536. The note about atoi_short() stays, because that one still reports "no digits" without reporting overflow. #326 replaces it with a version that does both, and this should move onto it once that lands.
This commit is contained in:
1 parent
ccafa01c74
commit
4db1ccbbd9
1 file changed
+3
-16
+3
-16
@@ -1460,28 +1460,15 @@ void parse_syslog(void)
|
||||
syslog_port_scratch = 0;
|
||||
syslog_port_idx = cmd_words_b[2];
|
||||
for (;;) {
|
||||
/* Plain comparisons instead of isnumber() in the loop
|
||||
* condition, and nested ifs instead of || and &&: either form
|
||||
* makes SDCC park a boolean in the bit area, and an image
|
||||
* carrying LACP and STP as well is one bit short of needing a
|
||||
* third byte of it - which would push everything up and stop
|
||||
* the link. */
|
||||
syslog_port_digit = cmd_buffer[syslog_port_idx];
|
||||
if (syslog_port_digit < '0')
|
||||
break;
|
||||
if (syslog_port_digit > '9')
|
||||
if (syslog_port_digit < '0' || syslog_port_digit > '9')
|
||||
break;
|
||||
syslog_port_digit -= '0';
|
||||
if (syslog_port_scratch > 6553) {
|
||||
if (syslog_port_scratch > 6553
|
||||
|| (syslog_port_scratch == 6553 && syslog_port_digit > 5)) {
|
||||
syslog_port_scratch = 0; /* too large - reject below */
|
||||
break;
|
||||
}
|
||||
if (syslog_port_scratch == 6553) {
|
||||
if (syslog_port_digit > 5) {
|
||||
syslog_port_scratch = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
syslog_port_scratch = syslog_port_scratch * 10 + syslog_port_digit;
|
||||
syslog_port_idx++;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user