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

Jan Engelhardt jengelh at inai.de
Tue Aug 10 21:41:40 UTC 2021


On Tuesday 2021-08-10 21:51, Paul Eggert wrote:
> On 8/9/21 3:55 PM, Jan Engelhardt wrote:
>
>> Inside tzload, if malloc fails, then, by POSIX standardese, it ought to set
>> errno. However, clang - rightfully, I think - does not make any particular
>> assumptions about malloc and has found and reported the case whereby this
>> malloc returns with NULL _and_ errno is 0.
>
> So I took the
> usual way out in the spirit of HAVE_POSIX_DECLS etc. by adding a compile-time
> option HAVE_MALLOC_ERRNO which you can set to 0 if your platform's malloc
> departs from standard practice. See the attached proposed patches.
> 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. Previously, there was a

	return errno;

now in 5c79ca1 there is a

	return HAVE_MALLOC_ERRNO ? errno : ENOMEM;

HAVE_MALLOC_ERRNO is a compile-time constant (set to 1 on POSIXy)
so you really just have the same thing as before.

If you have not yet been notified by github, my original 
(counter)proposal is in https://github.com/eggert/tz/pull/28 . *That* 
clears the clang report. It also does without any new compile-time 
define. It is easy to identify, as there just is no good reason for 
malloc(non-zero) to return NULL and not set errno - whether POSIX or 
not.


More information about the tz mailing list