Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an unused variable issue in nxt_term_parse() as found by clang-analyzer and coverity #1441

Merged
merged 2 commits into from
Sep 24, 2024

Commits on Sep 24, 2024

  1. 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 <[email protected]>
    ac000 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    b358e7f View commit details
    Browse the repository at this point in the history
  2. src/test: Add an extra test case to nxt_term_parse_test.c

    The function nxt_term_parse() is able to take strings with trailing
    whitespace e.g. "1w1d ", add a test case to cover such things.
    
    Signed-off-by: Andrew Clayton <[email protected]>
    ac000 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    a9d687e View commit details
    Browse the repository at this point in the history