[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

error.c triggers -Wformat-extra-args

From: Daniel E. Macks
Subject: error.c triggers -Wformat-extra-args
Date: Wed, 25 Jun 2014 18:08:54 +0000 (UTC)
User-agent: slrn/1.0.1 (Darwin)

Building gettext-0.19.1, which embeds copies of gnulib, on OS X 10.8,
which uses the clang compiler (via XCode-5.1), gives:

clang -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I..  -I../intl -I../intl 
error.o error.c
error.c:381:12: warning: data argument not used by format string 
           file_name, line_number);

The same construct is still present in error.c in gnulib git [1]:

#if _LIBC
  __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ",
              file_name, line_number);
  fprintf (stderr, file_name != NULL ? "%s:%d: " : " ",
           file_name, line_number);

In the case where file_name==NULL, the format-string is " " but
file_name and line_number are still passed. This may not be a
functional error [2], but it's an easy-to-clear warning, which will
help downstream users who build with -Werror or generally want cleaner
and quieter builds especially of code they don't control. Just have
whole alternative fprintf() with appropriate parameters in a
conditional if/else block rather than just conditional on the
format-string. Something like:

  if (file_name != NULL)
    fprintf (stderr, "%s:%d: ", file_name, line_number)
    fprintf (stderr, " ");

[1] http://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/error.c


Daniel Macks

reply via email to

[Prev in Thread] Current Thread [Next in Thread]