After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 720708 - g_assert_warning(): number of arguments doesn't match format string
g_assert_warning(): number of arguments doesn't match format string
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: build
2.39.x
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-12-19 00:10 UTC by Patrick Welche
Modified: 2014-06-28 17:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
avoid -Wformat-extra-args build errors (1.21 KB, patch)
2014-01-04 17:46 UTC, Patrick Welche
accepted-commit_now Details | Review

Description Patrick Welche 2013-12-19 00:10:22 UTC
The bulk of g_assert_warning() is:

  g_log (log_domain,
         G_LOG_LEVEL_ERROR,
         expression 
         ? "file %s: line %d (%s): assertion failed: (%s)"
         : "file %s: line %d (%s): should not be reached",
         file, 
         line, 
         pretty_function,
         expression);

If expression == NULL, then the above reduces to:

  g_log (log_domain,
         G_LOG_LEVEL_ERROR,
         "filer %s: line %d (%s): should not be reached",
         file, 
         line, 
         pretty_function,
         expression);

The format string expects 3 arguments, but 4 are given.

According to  http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
page 309 (327th of document):

    "If the format is exhausted while arguments remain, the excess
     arguments are evaluated (as always) but are otherwise ignored."

so the current code strictly speaking is legal. The downside is that you keep
seeing a false positive if you build with -Wformat-extra-args, which is a useful flag, as usually it just finds places where an argument was added, and the format string not updated.

Maybe we could change the code to the less cunning, but more compiler friendly:

  if (expression)
    g_log (log_domain,
           G_LOG_LEVEL_ERROR,
           "file %s: line %d (%s): assertion failed: (%s)"  
           file,
           line,
           pretty_function,
           expression);
  else
    g_log (log_domain,
           G_LOG_LEVEL_ERROR,
           "file %s: line %d (%s): should not be reached",  
           file,
           line,
           pretty_function);

?
Comment 1 Patrick Welche 2014-01-04 17:46:05 UTC
Created attachment 265319 [details] [review]
avoid -Wformat-extra-args build errors
Comment 2 Patrick Welche 2014-04-12 10:10:00 UTC
ping?
Comment 3 Allison Karlitskaya (desrt) 2014-04-13 12:52:27 UTC
This is an internally-used macro only.  I'd prefer if we could split it up into two separate macros instead.
Comment 4 Allison Karlitskaya (desrt) 2014-04-15 15:14:46 UTC
Review of attachment 265319 [details] [review]:

Sorry -- my mistake.  I thought this was a macro, not a deprecated function.

Please commit.