static analyzer false positive

Using the latest Clang static analyzer (SVN update yesterday) I got the following false positive error.

build\DXL\GoAheadWeb\webs.c:2429:3: warning: Value stored to ‘now’ is never read

now = sbuf->mtime;

^ ~~~~~~~~~~~

The function in questions is:

/*

  • Build an ASCII time string. If sbuf is NULL we use the current time,

  • else we use the last modified time of sbuf;

*/

char_t *websGetDateString(websStatType *sbuf)

{

char_t* cp, *r;

time_t now;

if (sbuf == NULL) {

time(&now);

} else {

now = sbuf->mtime;

}

if ((cp = gctime(&now)) != NULL) {

cp[gstrlen(cp) - 1] = ‘\0’;

r = bstrdup(B_L, cp);

return r;

}

return NULL;

}

The function gctime() in the following if statement condition does read the value of now. It seems like the analyzer may be assuming the function is passed the address of the variable now for writing only.

Hopefully this can help someone correct this type of false positive error report in the future.

Dennis,

Please, file a Bugzilla report (http://clang-analyzer.llvm.org/filing_bugs.html) and attach a preprocessed file so that we could reproduce.

Thanks,
Anna.

Hi Anna,

No need for a bug report. While preparing the preprocessed file you requested I discovered that gctime() was defined as NULL by a macro. No function was being called, and hence the error report was accurate.

Dennis Cote