Skip to content

Use %zu printf format for type size_t - #2976

Merged
allinurl merged 1 commit into
allinurl:masterfrom
edgar-bonet:size_t
Aug 5, 2026
Merged

Use %zu printf format for type size_t#2976
allinurl merged 1 commit into
allinurl:masterfrom
edgar-bonet:size_t

Conversation

@edgar-bonet

Copy link
Copy Markdown
Contributor

I am still using a 32-bit netbook, and even compiling stuff on it. Yes, I know it's outdated. While building goaccess, I got this GCC warning:

src/bin2c.c:119:39: warning: format ‘%lu’ expects argument of type ‘long unsigned int’,
but argument 4 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=]
  119 |   fprintf (f_output, "const char %s[%lu] = {", ident, file_size);
      |                                     ~~^               ~~~~~~~~~
      |                                       |               |
      |                                       |               size_t {aka unsigned int}
      |                                       long unsigned int
      |                                     %u

and the same warning on line 137.

This pull request fixes the printf format, which should be %zu.

On 32-bit environments, ‘size_t’ is a 32-bit type, whereas ‘unsigned
long’ is 64 bits long. As the %lu printf format expects an unsigned long
argument, it cannot be used portably with a size_t argument. Use the
proper %zu instead.

Fixes:
 * src/bin2c.c:119:39: warning: format ‘%lu’ expects argument of type
   ‘long unsigned int’, but argument 4 has type ‘size_t’ {aka ‘unsigned
   int’} [-Wformat=]
 * the same warning on line 137
@allinurl
allinurl merged commit 00a3c58 into allinurl:master Aug 5, 2026
17 checks passed
@allinurl

allinurl commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Awesome. Merged. Thank you!

@edgar-bonet
edgar-bonet deleted the size_t branch August 5, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants