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: Ben Pfaff
Subject: Re: INT_STRLEN_BOUND and locales with *printf
Date: Tue, 08 Feb 2011 12:52:27 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Paul Eggert <address@hidden> writes:

> 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.

Thanks.  I was assuming a plain format such as %d.

Does your answer come from experience with many implementations,
or is it based on knowledge of some document or standard?  I'd
like to be able to know why the answer is true, if I can.
-- 
Ben Pfaff 
http://benpfaff.org



reply via email to

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