Download raw body.
new warning in make
On Fri, Sep 26, 2025 at 12:55:59AM -0400, George Koehler wrote:
> On Thu, 25 Sep 2025 11:35:28 +0200
> Marc Espie <marc.espie.openbsd@gmail.com> wrote:
>
> > 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.
>
> Your diff is correct, but while we are here, I wonder if it should be
> "%-12lld" and (long long)time(NULL)?
>
> (Minor detail: maybe add an empty line under "char temp".)
>
> I tried to run the code, but the archive feature in make(1) is so
> broken that I had trouble reaching it. First, make(1) opens the wrong
> archive. I tried to touch a target named "stuff.a(one)", expecting it
> to open an archive named "stuff.a", but it instead opened an archive
> named "stuff.a(one)". Second, make(1) can't find members if the
> archive has a symbol table. I archived a text file with no symbols,
>
> $ cat Makefile
> stuff.a(one): one
> ar rcU stuff.a one
> ar rcU "stuff.a(one)" one
>
> Then make -t ignored "stuff.a" and touched "one" in "stuff.a(one)" and
> corrupted the time with a '\0', unless this diff fixed the truncation.
>
> I'm in no hurry to fix the name and symbol problems, as I do not use
> the archive feature.
> --gkoehler
Likewise, but silencing a warning that's correct is the best way to go.
Can you commit this (eventually with an extra blank line) and then
we'll bike-shed ? :D
> > 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));
> > + memcpy(arHeader.ar_date, temp, sizeof(arHeader.ar_date));
> > if (fseek(arch, -sizeof(struct ar_hdr), SEEK_CUR) == 0)
> > (void)fwrite(&arHeader, sizeof(struct ar_hdr), 1, arch);
> > fclose(arch);
> >
>
new warning in make