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

This reverts commit 4ae8606b6f. 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]: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3390
[2]: 44b3d5d80445234041f6c59feb89645f7102c3a4
[3]: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/770
[4]: https://gitlab.gnome.org/GNOME/glib/-/issues/1744

Signed-off-by: James Knight <james.d.knight@live.com>
This commit is contained in:
James Knight 2023-04-25 23:21:58 -04:00
parent c176fcf2eb
commit 0ca660315a

View File

@ -176,10 +176,11 @@ g_unix_connection_receive_fd (GUnixConnection *connection,
{ {
gint i; gint i;
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
ngettext ("Expecting 1 control message, got %d", ngettext("Expecting 1 control message, got %d",
"Expecting 1 control message, got %d", "Expecting 1 control message, got %d",
nscm)); nscm),
nscm);
for (i = 0; i < nscm; i++) for (i = 0; i < nscm; i++)
g_object_unref (scms[i]); g_object_unref (scms[i]);
@ -209,10 +210,11 @@ g_unix_connection_receive_fd (GUnixConnection *connection,
{ {
gint i; gint i;
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
ngettext ("Expecting one fd, but got %d\n", ngettext("Expecting one fd, but got %d\n",
"Expecting one fd, but got %d\n", "Expecting one fd, but got %d\n",
nfd)); nfd),
nfd);
for (i = 0; i < nfd; i++) for (i = 0; i < nfd; i++)
close (fds[i]); close (fds[i]);
@ -590,12 +592,13 @@ g_unix_connection_receive_credentials (GUnixConnection *connection,
{ {
if (nscm != 1) if (nscm != 1)
{ {
g_set_error_literal (error, g_set_error (error,
G_IO_ERROR, G_IO_ERROR,
G_IO_ERROR_FAILED, G_IO_ERROR_FAILED,
ngettext ("Expecting 1 control message, got %d", ngettext("Expecting 1 control message, got %d",
"Expecting 1 control message, got %d", "Expecting 1 control message, got %d",
nscm)); nscm),
nscm);
goto out; goto out;
} }