On Fri, Jul 05, 2024 at 09:38:21PM +0800, Xi Ruoyao via Gcc wrote:
> On Fri, 2024-07-05 at 15:03 +0200, Alejandro Colomar wrote:
> > ISO C specifies these APIs as accepting a restricted pointer in their
> > first parameter:
> > 
> > $ stdc c99 strtol
> > long int strtol(const char *restrict nptr, char **restrict endptr, int 
> > base);
> > $ stdc c11 strtol
> > long int strtol(const char *restrict nptr, char **restrict endptr, int 
> > base);
> > 
> > However, it should be considered a defect in ISO C.  It's common to see
> > code that aliases it:
> > 
> >     char str[] = "10 20";
> > 
> >     p = str;
> >     a = strtol(p, &p, 0);  // Let's ignore error handling for
> >     b = strtol(p, &p, 0);  // simplicity.
> 
> Why this is wrong?

I don't see anything wrong with it either.  The function only reads
the string starting with nptr and then stores some pointer to *endptr,
if the caller doesn't make nptr point to what endptr points to or vice
versa, that should be fine.

        Jakub

Reply via email to