Re: [PATCH v2 3/8] grep: typesafe versions of grep_source_init

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

 



On Fri, Aug 13, 2021 at 6:05 PM Jonathan Tan <jonathantanmy@xxxxxxxxxx> wrote:
>
> 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.)



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux