Re: snprintf heads-up

From: Date: Fri, 08 Sep 2000 14:22:18 +0000
Subject: Re: snprintf heads-up
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-32673@lists.php.net to get a copy of this message
On Fri, 8 Sep 2000, Jon Ribbens wrote: > Zeev Suraski <zeev@zend.com> wrote: > > Question is, what do we do about it. In my opinion, the most 'sensible > > behavior' would be snprintf() returning the actual amount of characters > > written. > > This behaviour is not particularly useful, because it means that if your > buffer turns out to be too small, and you want to extend it, you have no > way of knowing by how much you need to increase it. If you want to extend it, that's true. However, in my opinion, in most cases you use snprintf() to give a maximum limit to an existing buffer, and you wouldn't increase its length even if it overflows. snprintf() usually just comes to impose that reasonable length limit in a secure way. In this (general, IMHO) case, the most interesting piece of information would be the number of characters actually written, so that you don't have to go through strlen() again. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/

« previous php.dev (#32673) next »