Open pascal-cuoq opened 4 years ago
The header inttypes.h
provides macros such as, for instance, PRIi32
to print a value of type int32_t
which may be aliased to int
, long
, or something else. However POSIX provides no such facility for off_t
. Instead I would recommend:
printf("not a sequence %ld %d\n", (long)offset, num_certs);
This works at least as well as the original line. In general, the following works in more cases but requires including stdint.h
:
printf("not a sequence %jd %d\n", (intmax_t)offset, num_certs);
The file
src/main.c
defines variable aoffset
of typeoff_t
and prints it with%ld
:While it's a good idea to use the POSIX type
off_t
to represent the result of a call tolseek
, the functionprintf
only acceptslong
arguments for the%ld
format. Ifprintf
was not variadic, an implicit conversion would take place as per C11 6.5.2.2:7 (this is whycos(0)
works despite 0 having typeint
, as long as the prototype forcos
has been provided). Butprintf
is variadic and the compiler does no conversion for the arguments after its first one. Instead, the behavior is undefined if the expression passed for%ld
is not of typelong
.Frama-C's value analysis should warn for type mismatches in
printf
, but of course you need to apply it to the file for it to warn about this UB.