summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrew Clayton <a.clayton@nginx.com>2024-09-24 00:03:19 +0100
committerAndrew Clayton <a.clayton@nginx.com>2024-09-24 16:01:05 +0100
commitb358e7fb6af71ec44bb24acc21a21955f2052ff1 (patch)
tree0eb43df4087ff09b6de5d05682b615a771e2e869
parent355f038fdea54bb62fab942729b9386591d308b2 (diff)
downloadunit-b358e7fb6af71ec44bb24acc21a21955f2052ff1.tar.gz
unit-b358e7fb6af71ec44bb24acc21a21955f2052ff1.tar.bz2
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>
-rw-r--r--src/nxt_time_parse.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/nxt_time_parse.c b/src/nxt_time_parse.c
index 63620b09..1ac52fe4 100644
--- a/src/nxt_time_parse.c
+++ b/src/nxt_time_parse.c
@@ -317,7 +317,6 @@ nxt_term_parse(const u_char *p, size_t len, nxt_bool_t seconds)
enum {
st_first_digit = 0,
st_digit,
- st_letter,
st_space,
} state;
@@ -354,22 +353,17 @@ nxt_term_parse(const u_char *p, size_t len, nxt_bool_t seconds)
state = st_first_digit;
}
- if (state != st_letter) {
+ /* Values below '0' become >= 208. */
+ c = ch - '0';
- /* Values below '0' become >= 208. */
- c = ch - '0';
-
- if (c <= 9) {
- val = val * 10 + c;
- state = st_digit;
- continue;
- }
-
- if (state == st_first_digit) {
- return -1;
- }
+ if (c <= 9) {
+ val = val * 10 + c;
+ state = st_digit;
+ continue;
+ }
- state = st_letter;
+ if (state == st_first_digit) {
+ return -1;
}
switch (ch) {