apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <traw...@attglobal.net>
Subject Re: cvs commit: apr/strings apr_strings.c
Date Wed, 30 Jun 2004 13:17:58 GMT
Jim Jagielski wrote:
>>>apr_snprintf(buf, 5, "%3d ", (int) size);
>>>if (buf[3] != ' ') { /* catch overflow */
>>>     return strcpy(buf, "****");
>>>}
>>>
>>
>>If I understand the problem correctly, doesn't snprintf() return
>>the number of bytes that would have been printed if there had been
>>no limit. Thus, can't we check that the return value is <=
>>the actual buffer size?
>>

snprintf() is not as portable as we would like, so we need to use apr_snprintf()

> And apr_snprintf() tells us the same if len is 0.

so we'd have to call it twice...

I like Joe's suggestion of catching it in the test suite.  If the API is ever 
changed so that the caller specifies the length of their buffer, then there 
will be an interesting case which apr_snprintf() could catch.


Mime
View raw message