Re: [Code] Strange error.

From: Daniel A. Koepke (
Date: 01/10/03

On Sat, 11 Jan 2003, Thomas Arp wrote:

> Can't this be fixed by changing calls to snprintf to this?
> len += snprintf(MIN(sizeof(buf), buf+len),
>                 MIN(sizeof(buf), sizeof(buf)-len),
>                 "text here");

I take it you meant

    len += snprintf(buf + len, MAX(0, sizeof(buf) - len), "text here");

in which case, yes, mostly.  However, non-standard implementations of
snprintf(), such as that in older glibc versions, return -1 if the string
to be printed wouldn't fit.  On these platforms, this version could
overflow.  For a portable solution, look at how George did it in stock


   | FAQ: |
   | Archives: |
   | Newbie List:   |

This archive was generated by hypermail 2b30 : 06/26/03 PDT