This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] error, warn, warnx: Use __fxprintf for wide printing [BZ #23519]
- From: "Gabriel F. T. Gomes" <gabriel at inconstante dot eti dot br>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: <libc-alpha at sourceware dot org>
- Date: Tue, 14 Aug 2018 10:22:20 -0300
- Subject: Re: [PATCH] error, warn, warnx: Use __fxprintf for wide printing [BZ #23519]
- References: <20180814120325.5D500405971E1@oldenburg.str.redhat.com>
On Tue, 14 Aug 2018, Florian Weimer wrote:
> void
> vwarnx (const char *format, __gnuc_va_list ap)
> {
> flockfile (stderr);
>- if (_IO_fwide (stderr, 0) > 0)
>- {
>- __fwprintf (stderr, L"%s: ", __progname);
>- convert_and_print (format, ap);
>- putwc_unlocked (L'\n', stderr);
>- }
>- else
>- {
>- fprintf (stderr, "%s: ", __progname);
>- if (format)
>- vfprintf (stderr, format, ap);
>- putc_unlocked ('\n', stderr);
>- }
>+ __fxprintf (stderr, "%s: ", __progname);
>+ if (format)
>+ __vfxprintf (stderr, format, ap);
>+ __fxprintf (stderr, "\n");
Is it true that you can remove the call to 'convert_and_print' because
__fxprintf and __vfxprintf already check the wideness of the output and
convert (indirectly via locked_vfxprintf)?
It appears so, and your patch looks good to me.
>--- a/misc/error.c
>+++ b/misc/error.c
>@@ -203,72 +203,14 @@ static void _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) _GL_ARG_NONNULL ((3))
> error_tail (int status, int errnum, const char *message, va_list args)
> {
> #if _LIBC
>+ int ret = __vfxprintf (stderr, message, args);
>+ if (ret < 0 && errno == ENOMEM && _IO_fwide (stderr, 0) > 0)
>+ /* Leave a trace in case the heap allocation of the message string
>+ failed. */
>+ fputws_unlocked (L"out of memory\n", stderr);
>+#else
>+ vfprintf (stderr, message, args);
> #endif
Just out of curiosity, how do we know that other programs use this code
outside of glibc? (assuming this is the reason for the _LIBC check).