[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Remove deps on *printf(3) in libltdl
From: |
Paolo Bonzini |
Subject: |
Re: Remove deps on *printf(3) in libltdl |
Date: |
Tue, 04 Jan 2005 10:08:26 +0100 |
User-agent: |
Mozilla Thunderbird 0.9 (Macintosh/20041103) |
Pending use of strl*, yes, please go right ahead. Also, please add
a note to TODO about conformance testing of *.c (insofar as is possible
within the limits of our testsuite framework), and a note in HACKING
to mention that we should take advantage of strl* consistently
throughout libltd now that we have them at our disposal.
I consider strl* more a source of bugs than anything else. Much better
if they were coded something like
size_t
strlcpy (char *dest, char *src, size_t n)
{
size_t src_len = 0;
while (n-- > 0)
if ((*dest++ = *src++) == '\0')
return src_len;
else
src_len++;
abort ();
}
char *
strlcat (char *dest, char *src, size_t n)
{
int dest_len = strlen (dest);
if (n <= dest_len)
/* Know your buffer lengths! */
abort ();
return dest_len + strlcpy (dest + dest_len, src, n - dest_len);
}
i.e., fail loudly if SRC is longer than N bytes. strlcpy were born to
paper over fixed-size buffers, not to use them together with malloc.
All this without taking into consideration the implicit quadratic
behavior of strlcat, which is perfectly avoidable thanks to the return
value of strlcpy.
Paolo
- Re: Remove deps on *printf(3) in libltdl,
Paolo Bonzini <=