On Mon, Sep 8, 2008 at 9:31 AM, Allison Randal via RT
<[EMAIL PROTECTED]> wrote:
> Agreed that this particular ticket is not useful. Resolve it and replace
> it with a [CAGE] ticket with explicit instructions on converting all
> existing 'sprintf', 'strcat', etc calls with calls to 'snprintf',
> 'strlcat', etc. (Also include a list of all calls that should be converted.)
I disagree on the "all" part. strlcat and strlcpy are not always the
best repalcement. When the C string length is known memcpy is a
simpler and faster solution.
For example in config/gen/platform/generic/env.c we have:
int name_len = strlen(name);
int val_len = strlen(value);
char *envs = malloc(name_len + 1 + val_len + 1);
if (envs == NULL)
return;
/* Save a bit of time, by using the fact we already have the
lengths, avoiding strcat */
strcpy(envs, name);
strcpy(envs + name_len, "=");
strcpy(envs + name_len + 1, value);
The memcpy way can be:
memcpy(envs, name, name_len);
envs[name_len] = '=';
memcpy(envs + name_len + 1, value, val_len + 1);
This code can be encapsulated on a function or a macro, and add inside
it checks for non-nullness and lengths in debug builds.
Regarding snprintf, according linux man page is in the C99, BSD and
XOPEN standards, not on older ansi C, and I think we don't have that
as a requirement for the C compiler usable to build parrot. And a
replacement for this is not so easy to write and test as the others.
--
Salu2