Skip to content

Clang static code analyser: The left operand of '!=' is a garbage value #208

Description

@DimitriPapadopoulos

The Clang static code analyser emits a warning:

$ scan-build clang -c ini.c 
scan-build: Using '/usr/lib/llvm-18/bin/clang' for static analysis
ini.c:164:56: warning: The left operand of '!=' is a garbage value [core.UndefinedBinaryOperatorResult]
  164 |         if (offset == max_line - 1 && line[offset - 1] != '\n') {
      |                                       ~~~~~~~~~~~~~~~~ ^
1 warning generated.
scan-build: Analysis run complete.
scan-build: 1 bug found.
scan-build: Run 'scan-view /tmp/scan-build-2026-01-05-114423-34279-1' to examine bug reports.
$ 

While it looks like a false positive, it would be nice to silence the warning message. One way to do that would be to initialise line in ini_reader_string:

#ifdef __clang_analyzer__
    memset(str, '\0', num);
#endif

See also openconnect/ocserv#437.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions