Index | Thread | Search

From:
Christian Schulte <cs@schulte.it>
Subject:
Re: new warning in make
To:
millert@openbsd.org, tech@openbsd.org
Date:
Fri, 26 Sep 2025 11:03:56 +0200

Download raw body.

Thread
  • Christian Schulte:

    new warning in make

  • Christian Schulte:

    new warning in make

  • Am 25.09.2025 um 11:35 schrieb Marc Espie:
    > cc now warns over arch.c
    > /usr/src/usr.bin/make/arch.c:839:3: warning: 'snprintf' will always be truncated; specified size is 12, but format string expands to at least 13 [-Wformat-truncation]
    >   839 |                 snprintf(arHeader.ar_date, sizeof(arHeader.ar_date),
    >       |                 ^
    > 
    > 
    > Pretty sure it's correct, considering that snprintf will truncate with a 0.
    > 
    > Printing to a temp buffer and copying only the string ought to fix it
    > if I'm not mistaken.
    > 
    > Index: arch.c
    > ===================================================================
    > RCS file: /vide/cvs/src/usr.bin/make/arch.c,v
    > diff -u -p -r1.94 arch.c
    > --- arch.c	4 Sep 2023 11:35:11 -0000	1.94
    > +++ arch.c	25 Sep 2025 09:33:07 -0000
    > @@ -836,8 +836,9 @@ ArchTouch(const char *archive, const cha
    >  
    >  	arch = ArchFindMember(archive, member, &arHeader, "r+");
    >  	if (arch != NULL) {
    > -		snprintf(arHeader.ar_date, sizeof(arHeader.ar_date),
    > -		    "%-12ld", (long) time(NULL));
    > +		char temp[sizeof(arHeader.ar_date)+1];
    > +		snprintf(temp, sizeof(temp), "%-12ld", (long) time(NULL));
    
    I am really not sure but I think this should read "%-12" PRIdMAX,
    (intmax_t)time(NULL));
    
    Just my 2 cents.
    
    -- 
    Christian
    
    
  • Christian Schulte:

    new warning in make

  • Christian Schulte:

    new warning in make