Hi Bruno,

On 2026-02-27T08:54:51+0100, Bruno Haible wrote:
> Alejandro Colomar wrote:
> > I've added the following text in strcspn(3):
> > 
> >             It is equivalent to
> > 
> >                 (strpbrk(s, reject) ?: strnul(s)) ‐ s
> 
> It's a useful addition, because some (many?) programmers grasp formulas more
> easily that they grasp words.

Yup.

> >     $ MANWIDTH=64 diffman-git 6c600ed9a9bc HEAD | grep -v ^-
> >     +++ HEAD:man/man3/stpcpy.3
> >     @@ -24,18 +24,10 @@ DESCRIPTION
> >           stpcpy() is similar to strcpy(3), but returns a pointer to
> >           the terminating null byte in dst.
> >      
> >     +     It is equivalent to both of the following expressions:
> >      
> >     +         memset(mempcpy(dst, src, strlen(src)), '\0', 1);
> >     +         strcpy(dst, src) + strlen(dst)
> 
> The latter formula depends on the (undefined) order of evaluation.
> Better write it as
>                     strcpy(dst, src) + strlen(src)

Hmmm, thanks!  Fixed.

        commit 9cc58fbb9c1b8fee22766c4cfe03e9faa5f36c7a (HEAD -> contrib)
        Author: Alejandro Colomar <[email protected]>
        Date:   2026-03-03 01:41:07 +0100

            man/man3/stpcpy.3: Fix UB in expression
            
            The order of evaluation is undefined, so we must use a length that 
is
            stable.
            
            Reported-by: Bruno Haible <[email protected]>
            Suggested-by: Bruno Haible <[email protected]>
            Signed-off-by: Alejandro Colomar <[email protected]>

        diff --git a/man/man3/stpcpy.3 b/man/man3/stpcpy.3
        index bff56d4c..de89a58f 100644
        --- a/man/man3/stpcpy.3
        +++ b/man/man3/stpcpy.3
        @@ -40,7 +40,7 @@ .SH DESCRIPTION
         .in +4n
         .EX
         memset(mempcpy(dst, src, strlen(src)), \[aq]\[rs]0\[aq], 1);
        -strcpy(dst, src) + strlen(dst)
        +strcpy(dst, src) + strlen(src)
         .EE
         .in
         .SH RETURN VALUE

> 
> >     +++ HEAD:man/man3/stpncpy.3
> >     @@ -36,23 +36,16 @@ DESCRIPTION
> >           ter sequence is truncated.  For the difference between the
> >           two functions, see RETURN VALUE.
> >      
> >     +     strncpy()
> >     +            It is equivalent to
> >      
> >     +                stpncpy(dst, src, dsize), dst
> >      
> >     +     stpncpy()
> >     +            It is equivalent to
> >      
> >     +                memset(mempcpy(dst, src, strnlen(src, dsize)), '\0',
> >     +                       dsize - strnlen(src, dsize))
> >      
> >      RETURN VALUE
> >           strncpy()
> 
> This is correct. But it's redundant with the already existing section
> "An implementation of these functions might be: ..."

I've replaced that.  Now it uses less screen to say the same.


Have a lovely night!
Alex

> 
> Bruno
> 
> 
> 

-- 
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature

Reply via email to