[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: (ITS#4467) snprintf is consistenly used wrongly
On Sun, 2006-04-02 at 15:01 +0000, h.b.furuseth@usit.uio.no wrote:
> Full_Name: Hallvard B Furuseth
> Version: HEAD
> OS:
> URL:
> Submission from: (NULL) (129.240.186.42)
> Submitted by: hallvard
>
>
> OpenLDAP is full of code like
> ptr += snprintf( ptr, ... );
> and
> bv.bv_len = snprintf( ... );
> <use bv>;
>
> However snprintf does not return the number of characters written, it
> returns the number of characters it would write if no truncation occurs,
> not including the terminating '\0'.
In many cases, especially when used to compute the length of a berval,
snprintf is used under the assumption the buffer is large enough to
contain the formatted output, based on the knowledge of the value that
is about to be printed. For example, when used to format integers, the
buffer is usually created as
char buf[] = "18446744073709551615UL";
which is the string representation of ULONG_MAX, or anything like that.
In general, I concur a more consistent and reliable usage of that
function should occur throughout the code.
p.
Ing. Pierangelo Masarati
Responsabile Open Solution
OpenLDAP Core Team
SysNet s.n.c.
Via Dossi, 8 - 27100 Pavia - ITALIA
http://www.sys-net.it
------------------------------------------
Office: +39.02.23998309
Mobile: +39.333.4963172
Email: pierangelo.masarati@sys-net.it
------------------------------------------