[PATCH] error, warn, warnx: Use __fxprintf for wide printing [BZ #23519]
Florian Weimer
fweimer@redhat.com
Tue Aug 14 13:46:00 GMT 2018
On 08/14/2018 03:22 PM, Gabriel F. T. Gomes wrote:
> 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)?
Correct. I failed to convert an fputs_unlocked call.
I'm also adding a test in the attached patch.
>> --- 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).
In these cases, it is useful to check gnulib. Often, there is a copy of
the code there as well, and there is an expectation that we keep merging
from gnulib (but this is not always possible).
Thanks,
Florian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: warn.patch
Type: text/x-patch
Size: 10152 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20180814/917806b2/attachment.bin>
More information about the Libc-alpha
mailing list