[tz] tzcode: uninitialized sp->charcnt gives clang analyzer warning

Paul Eggert eggert at cs.ucla.edu
Tue Aug 10 23:11:21 UTC 2021


On 8/10/21 2:41 PM, Jan Engelhardt wrote:

>> With these patches you should be able to run clang this way:
>>
>>   clang --analyze -Xanalyzer -analyzer-output=text localtime.c \
>>     -DALL_STATE -DHAVE_MALLOC_ERRNO=0
>>
>> and get a clean report.
> 
> Certainly not.

Did you actually try it? It worked for me. I am using clang 12.0.0 
(Fedora 12.0.0-2.fc34) on x86-64. The key is that -DHAVE_MALLOC_ERRNO=0 
option.

> If you have not yet been notified by github, my original
> (counter)proposal is in https://github.com/eggert/tz/pull/28 .

Patches like those are best circulated on this mailing list, as I don't 
often look at GitHub requests. (I wish there was some way to for GitHub 
to inform patch-submitters of this, but there doesn't seem to be.)

Anyway, the counterproposal doesn't solve the problem portably. On 
platforms where malloc does not conform to POSIX, errno might be garbage 
after malloc fails, and tzalloc etc. shouldn't communicate that garbage 
to its callers when tzalloc fails in turn. Conversely, an alternative 
approach in which tzalloc always sets errno to ENOMEM on malloc failure 
would lose useful information on POSIX platforms where malloc failures 
can yield errno values other than ENOMEM.

Something like HAVE_MALLOC_ERRNO is needed if localtime.c both (a) 
properly reports valid errno info and (b) ports to POSIX as well as to 
these non-POSIX platforms. This is because localtime.c's code cannot 
reliably distinguish between the two kinds of platforms simply by using 
runtime tests.


More information about the tz mailing list