Skip to content

restore error messages in gunixconnection while maintaining older compiler support

Revert "Fix error format in gio/gunixconnection.c (part 2)"

This reverts commit 4ae8606b. The idea for the change [1] was to address a build error for certain compilers that trigger a format-nonliteral error-promoted-warning since these compilers do not gracefully support ngettext usage. The changes following a pattern from an old commit [2]; however, James Hilliard has pointed out these changes do not work as intended. A deeper inspection of the commit showed that the commit was from an old merge request that was not pulled in, detailing why the changes did not work (see also [3][4]).

Manipulating the sockets unit test confirms that the format values no longer get a proper value:

...
ok 9 /socket/address
ok 10 /socket/unix-from-fd
ok 11 /socket/unix-connection
**
GLib-GIO:ERROR:../gio/tests/socket.c:1493:test_unix_connection_ancillary_data: assertion failed (err == NULL): Expecting one fd, but got %d
 (g-io-error-quark, 0)
...

And reverting this change restores the original functionality:

...
ok 9 /socket/address
ok 10 /socket/unix-from-fd
ok 11 /socket/unix-connection
**
GLib-GIO:ERROR:../gio/tests/socket.c:1493:test_unix_connection_ancillary_data: assertion failed (err == NULL): Expecting 1 control message, got 0 (g-io-error-quark, 0)
...

[1]: !3390 (merged) [2]: 44b3d5d8 [3]: !770 (closed) [4]: #1744 (closed)

gio: switch gunixconnection ngettext with g_dngettext calls

This commit changes the use of ngettext with g_dngettext. The project defined g_dngettext (with domain support) provides the same functionality as ngettext with a NULL domain provided. The purpose of this change is to help address a build error for certain compilers that trigger a format-nonliteral error-promoted-warning when using ngettext (see also [1][2]). The benefit of switching to use g_dngettext is that the function is defined with G_GNUC_FORMAT. This provides a hint to GNU GCC compilers to still sanity check these arguments, but not generate a format-nonliteral.

[1]: 4ae8606b [2]: 0ca66031

Testing

The combination of these two commits have to checked to ensure the format options work as expected. Testing was checked using ./build/gio/tests/socket application, with an interim manipulation to g_unix_connection_receive_fd to trigger the failure case which triggers this error. Inspection shows that the resulting error message is formatted as expected:

ok 10 /socket/unix-from-fd
ok 11 /socket/unix-connection
**
GLib-GIO:ERROR:../gio/tests/socket.c:1493:test_unix_connection_ancillary_data: assertion failed (err == NULL): Expecting 1 control message, got 0 (g-io-error-quark, 0)
not ok /socket/unix-connection-ancillary-data - GLib-GIO:ERROR:../gio/tests/socket.c:1493:test_unix_connection_ancillary_data: assertion failed (err == NULL): Expecting 1 control message, got 0 (g-io-error-quark, 0)
Bail out!

Compilation of glib worked in a host environment using GCC 12.2.1. These changes fix a build error observed when using GCC 11.3 (ARM).

Merge request reports