binclude.c: Change format of written length from %d to %zu
binclude.c: ensure path string is terminated
Makefile: Have util/binclude depend on its source file
Because int and size_t are different types, GCC's printf format
string checking warns when attempting to print one as the other.
util/binclude.c: In function ‘main’:
util/binclude.c:84:17: warning: format ‘%d’ expects argument of type
‘int’, but argument 2 has type ‘size_t {aka long unsigned int}’
[-Wformat=]
printf("Wrote %d bytes to \"%s\".\n", bytes_written, out_fpath);
~^
%ld
But when I made this change, binclude didn't automatically rebuild:
$ make util/binclude
make: 'util/binclude' is up to date.
I found and fixed a missing prerequisite in the makefile.
Finally, snprintf does not NUL terminate the result if the result is
exactly as long as the buffer. Work around this by passing 1 less
than the length of the buffer and explicitly write the terminator.
%d
to%zu
Because
int
andsize_t
are different types, GCC'sprintf
format string checking warns when attempting to print one as the other.So instead of
%d
which meansint
, use C99's%zu
which meanssize_t
. https://stackoverflow.com/q/2524611/2738262But when I made this change, binclude didn't automatically rebuild:
I found and fixed a missing prerequisite in the makefile.
Finally,
snprintf
does not NUL terminate the result if the result is exactly as long as the buffer. Work around this by passing 1 less than the length of the buffer and explicitly write the terminator.