bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: INT_STRLEN_BOUND and locales with *printf


From: Paul Eggert
Subject: Re: INT_STRLEN_BOUND and locales with *printf
Date: Tue, 08 Feb 2011 12:47:45 -0800
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7

On 02/08/11 12:34, Ben Pfaff wrote:
> The INT_STRLEN_BOUND macro in Gnulib's intprops.h calculates the
> maximum number of bytes in a formatted integer, on the basis that
> the minus sign and each digit will occupy one byte.  If *printf
> is used for formatting integers, is this a good assumption
> outside of the C locale?

Yes and no.  It's safe for %d, but it's not safe for arbitrary
formats.  This is true even in the C locale; for example, %1000d
is not safe for INT_STRLEN_BOUND.  Any code that uses
INT_STRLEN_BOUND with weird formats like %Id or %'d or %1000d
is busted and should get fixed.

It might be nice to have another macro INT_LOCALE_STRLEN_BOUND
or something like that, which would be large enough so that you
could use printf with any flags you like, no matter what locale,
so long as you don't specify a width.  I don't offhand know how
to write such a macro portably, though.  (Multiply
INT_STRLEN_BOUND by 16, maybe?  :-)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]