Re: [PATCH v2 3/8] grep: typesafe versions of grep_source_init
- From
Matheus Tavares Bernardino <matheus.bernardino@usp.br>
- Date
- Aug 16, 2021, 15:06 UTC
- Message-ID
- <CAHd-oW4BruuST61WqguX8Ror0sMmcaErXykv4B5Qb2tv8rszcw@mail.gmail.com>
- In-Reply-To
- <aa3f1f3c8908bd497ef506db466fc123eaccf21d.1628888668.git.jonathantanmy@google.com>
On Fri, Aug 13, 2021 at 6:05 PM Jonathan Tan <jonathantanmy@google.com> wrote:
Show 23 quoted lines
>
> diff --git a/grep.c b/grep.c
> index 424a39591b..8a8105c2eb 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -1840,28 +1850,28 @@ int grep_buffer(struct grep_opt *opt, char *buf, unsigned long size)
> return r;
> }
>
> -void grep_source_init(struct grep_source *gs, enum grep_source_type type,
> - const char *name, const char *path,
> - const void *identifier)
> +void grep_source_init_file(struct grep_source *gs, const char *name,
> + const char *path)
> {
> - gs->type = type;
> + gs->type = GREP_SOURCE_FILE;
> gs->name = xstrdup_or_null(name);
> gs->path = xstrdup_or_null(path);
> gs->buf = NULL;
> gs->size = 0;
> gs->driver = NULL;
> + gs->identifier = xstrdup(path);At first, it seemed a bit odd to me that we use `xstrdup_or_null(path)` first but `xtsrdup(path)` later. But, I saw that we already did this before this patch, and that the second call is fine as `path` is required to be non-NULL in this case (i.e. GREP_SOURCE_FILE), because we need it for grep_source_load_file() later. (Also, the only caller is correctly passing a non-NULL buffer, so all is good.)