bugGNU gettext - Bugs: bug #64384, *printf() replacements break...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #64384: *printf() replacements break -Wformat

Submitter:  Pierre Ossman <cendossm>
Submitted:  Wed 05 Jul 2023 02:21:09 PM UTC
   
 
Category:  Programmer interface Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  haible
Open/Closed:  Closed

Thu 14 Sep 2023 02:13:11 PM UTC, comment #1: 

Thanks for the report and suggestion.
Implemented through https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=commitdiff;h=a36d1168bb8a3950982ad7b13e72c86c7e4458ca

Test case:

#include <stdio.h>
#include <libintl.h>

int main ()
{
  printf ("missing: %d %d\n", 42);
  printf ("wrong: %llx\n", 17);
}


Compilation on mingw:
Before:

$ $CC -I /usr/local/mingw64/include -Wall -S foo.c


After:

$ $CC -I /usr/local/mingw64/include -Wall -S foo.c
foo.c: In function ‘main’:
foo.c:6:25: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=]
   printf ("missing: %d %d\n", 42);
                         ^
foo.c:7:22: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘int’ [-Wformat=]
   printf ("wrong: %llx\n", 17);
                      ^


Bruno Haible <haible>
Group administrator
Wed 05 Jul 2023 02:21:09 PM UTC, original submission:  

If the replacements *printf() functions (e.g. libintl_printf()) are active, then gcc correctly deduces that those are not the same as the standard *printf() functions. As such, it doesn't apply the standard checks that are enabled by -Wformat.

This is bad, since you lose all that type checking and fail to catch buggy calls.

You can work around it by doing this:

#if defined(_GNUC_) && defined(printf)
extern int fprintf (FILE , const char , ...)
  _attribute_((_format_ (_printf_, 2, 3)));
extern int printf (const char *, ...)
  _attribute_((_format_ (_printf_, 1, 2)));
extern int sprintf (char , const char , ...)
  _attribute_((_format_ (_printf_, 2, 3)));
extern int snprintf (char , size_t, const char , ...)
  _attribute_((_format_ (_printf_, 3, 4)));
extern int asprintf (char *, const char , ...)
  _attribute_((_format_ (_printf_, 2, 3)));
#endif
#if defined(_GNUC_) && defined(wprintf)
extern int fwprintf (FILE , const wchar_t , ...)
  _attribute_((_format_ (_printf_, 2, 3)));
extern int wprintf (const wchar_t *, ...)
  _attribute_((_format_ (_printf_, 1, 2)));
extern int swprintf (wchar_t , size_t, const wchar_t , ...)
  _attribute_((_format_ (_printf_, 3, 4)));
#endif

Pierre Ossman <cendossm>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by haible (Posted a comment)
  • -email is unavailable- added by cendossm (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-09-14 haible CategoryBuild Programmer interface
        StatusNone Fixed
        Assigned toNone haible
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.12.
    Corresponding source code