[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-grep] search.c clean-up

From: Jim Meyering
Subject: Re: [bug-grep] search.c clean-up
Date: Wed, 24 Nov 2004 12:29:51 +0100

Elliott Hughes <address@hidden> wrote:
>> The problem with the 4-parameter approach
>>   static void
>>   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?

I disagree.
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.

With that in mind, you might even argue that my change
should have preserved the pattern's unused trailing NUL byte.

> "static char* wrap_pattern(const char* pattern, const char* prefix,
> const char* suffix)" seems reasonable to me.
> or rename search.c as search.cpp and use std::string. all this
> pretending a char* is a string is *so* 1970s. (see also the comment
> starting "The PCRE interface doesn't allow NUL bytes in the pattern..."
> in the same file.)

Being limited by C is indeed frustrating.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]