[cfe-dev] Does clang static analyzer UndefResultChecker.cpp has false positive?

Jean Lee xiaoyur347 at gmail.com
Sun Oct 20 00:57:50 PDT 2013


My environment:
LLVM 3.3 + CLANG 3.3


Build command:
CHECKER="-enable-checker alpha.unix.Stream -enable-checker
alpha.unix.SimpleStream -enable-checker alpha.core.SizeofPtr
-enable-checker alpha.unix.cstring.BufferOverlap -enable-checker
alpha.security.ArrayBoundV2 -enable-checker alpha.unix.PthreadLock"

scan-build-3.3 ${CHECKER} g++ static_analyzer.cpp -pthread


2013/10/20 Jean Lee <xiaoyur347 at gmail.com>

> #include <stdio.h>
> void FunctionFread(const char* szFile)
> {
> FILE *fp = fopen(szFile, "rb");
> if (fp == NULL)
>  {
> return;
> }
>  int ofs[2], len;
> int nReadNum = fread( ofs, sizeof(int), 2, fp );
>
> if ( nReadNum != 2 )
>  {
> fclose(fp);
> return;
> }
>  // warning: The left operand of '-' is a garbage value
> len = ofs[1] - ofs[0];
>  printf("length=%d\n", len);
> fclose(fp);
> }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131020/f389d437/attachment.html>


More information about the cfe-dev mailing list