Re: search.c clean-up
On Nov 24, 2004, at 03:29, Jim Meyering wrote:
Elliott Hughes <enh@xxxxxxxxxxx> wrote:
The problem with the 4-parameter approach
wrap_pattern (char *pattern, size_t *pattern_len,
char const *prefix, char const *suffix)
is that it works fine when we don't have to free the PATTERN,
but if anyone ever calls it with a malloc'd PATTERN, it will leak.
return char*, and -- at the risk of more nitpickery -- expect the user
to call strlen if they need to know how long the pattern is?
A factorization change should avoid changing semantics.
If you want to declare that patterns do not contain NUL bytes
and adjust all of the corresponding interfaces, then belongs
in a separate change.
i did think about that when i pasted in the comment from Pcompile, but
didn't think it was significant because grep's already pretty uneven in
that area. even if bash(1) used a real string type to allow '\0' in
arguments, the char* argv mechanism doesn't let you transfer them,
the length passed to the compile function by grep's main comes from
strlen(3) if it's a bare argument, probably correctly handles patterns
containing '\0' if they came from a file, but uses strcpy(3) if they
came from '-e'.