Skip to content

Commit b358e7f

Browse files
committed
Resolve unused assignment in nxt_term_parse()
Both clang-analyzer and coverity flagged an issue in nxt_term_parse() that we set 'state = st_letter' but then set it to 'state = st_space' before using it. While we could simply remove the first assignment and placate the analyzers, upon further analysis it seems that there is some more cleanup that could be done in this function. This commit addresses the above issue, subsequent commits will continue the cleanup. To solve the unused assignment issue we can get rid of the 'state == st_letter' assignment and unconditionally execute the code that was behind the if (state != st_letter) { guard. If we're not handling a space then we should have either a digit or letter. Also, perhaps more importantly, this if () statement would never be false at this point as state would never == st_letter. We may as well also remove the st_letter enum value. The src/test/nxt_term_parse_test.c still passes tests: [notice] term parse test passed NOTE: Although this function is not currently used in Unit (only by src/test/nxt_term_parse_test.c), it is probably worth cleaning it up and solving one of the open clang-analyzer (and coverity) issues. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
1 parent 355f038 commit b358e7f

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/nxt_time_parse.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ nxt_term_parse(const u_char *p, size_t len, nxt_bool_t seconds)
317317
enum {
318318
st_first_digit = 0,
319319
st_digit,
320-
st_letter,
321320
st_space,
322321
} state;
323322

@@ -354,22 +353,17 @@ nxt_term_parse(const u_char *p, size_t len, nxt_bool_t seconds)
354353
state = st_first_digit;
355354
}
356355

357-
if (state != st_letter) {
356+
/* Values below '0' become >= 208. */
357+
c = ch - '0';
358358

359-
/* Values below '0' become >= 208. */
360-
c = ch - '0';
361-
362-
if (c <= 9) {
363-
val = val * 10 + c;
364-
state = st_digit;
365-
continue;
366-
}
367-
368-
if (state == st_first_digit) {
369-
return -1;
370-
}
359+
if (c <= 9) {
360+
val = val * 10 + c;
361+
state = st_digit;
362+
continue;
363+
}
371364

372-
state = st_letter;
365+
if (state == st_first_digit) {
366+
return -1;
373367
}
374368

375369
switch (ch) {

0 commit comments

Comments
 (0)