Re: replace strtok()

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: Alexander Lakhin <exclusion(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: replace strtok()
Date: 2024-10-16 11:14:29
Message-ID: CAEudQAqt7=deGjdfQXRjzQA+yAcAuSjkrsVhbmNjs2zcp=Rq-A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Em qua., 16 de out. de 2024 às 04:45, Peter Eisentraut <peter(at)eisentraut(dot)org>
escreveu:

> On 15.10.24 14:07, Ranier Vilela wrote:
> > I also wonder, if other places touched by 5d2e1cc11 need corrections
> > too.
> > I played with
> > PG_COLOR=always PG_COLORS="error=01;31" .../initdb
> >
> > and it looks like this free() call in pg_logging_init():
> > char *colors = strdup(pg_colors_env);
> >
> > if (colors)
> > {
> > ...
> > while ((token = strsep(&colors, ":")))
> > {
> > ...
> > }
> >
> > free(colors);
> > }
> > gets null in colors.
> >
> > Yeah, I also saw this usage, but I was waiting for a definition for the
> > first report.
> > The solution IMO, would be the same.
> >
> > diff --git a/src/common/logging.c b/src/common/logging.c
> > index aedd1ae2d8..45b5316d48 100644
> > --- a/src/common/logging.c
> > +++ b/src/common/logging.c
> > @@ -121,7 +121,7 @@ pg_logging_init(const char *argv0)
> > {
> > char *token;
> >
> > - while ((token = strsep(&colors, ":")))
> > + while ((token = strsep(&colors, ":")) != NULL && colors != NULL)
> > {
> > char *e = strchr(token, '=');
> > The advantage of this change is that it would avoid processing
> > unnecessary tokens.
>
> This wouldn't fix anything, I think. If colors is NULL, then strsep()
> already returns NULL, so the added code does nothing.
>
If *colors* is NULL, then the delimiter is not found and strsep will return
the entire
string **stringp, so the token becomes invalid*.

IMO, I think it must be necessary to check if *colors* are NULL too.

best regards,
Ranier Vilela

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrei Zubkov 2024-10-16 11:17:38 Re: Vacuum statistics
Previous Message Fujii Masao 2024-10-16 11:03:21 Re: Add “FOR UPDATE NOWAIT” lock details to the log.