talloc_asprintf dumping the length?

Volker Lendecke Volker.Lendecke at SerNet.DE
Thu Aug 10 11:01:22 GMT 2006


In an ltrace I just found

vsnprintf("", 1, "KEY/%d/%s", 0xbfa93a58) = 11 <0.000042>
malloc(60)                 = 0x8442b40 <0.000040>
vsnprintf("KEY/2/65534", 12, "KEY/%d/%s", 0xbfa93a58) = 11 <0.000041>
strlen("KEY/2/65534")      = 11 <0.000040>

To me it looks a bit silly to do the strlen after we've been
told by the lib already how long the string is. Looking at
the printf family of functions these all return the number
of bytes they printed.

Looking at our code this comes from the use of

What's the design decision behind talloc_asprintf dropping
this information? Code-wise it does not gain us much, we
have to check for NULL anyway. So we have to store the
result in a variable.

It's probably negligible on the indiviual call, but in the
big sum it could make a difference.

Asked differently: Would anybody object if I changed the
talloc_asprintf to

int talloc_asprintf(const void *t, char **res, const char *fmt, ...)

Or do you think it's better to have a new function? What
should the name of a new one be?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20060810/0d6589d5/attachment.bin

More information about the samba-technical mailing list