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? :-)
