[hackers] [sbase] tar: avoid unnecessary VLA || Michael Forney

From: <git_AT_suckless.org>
Date: Tue, 17 Mar 2026 10:48:43 +0100 (CET)

commit 20e44f4bcc2bda061dc801c820345628e05b5900
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Tue Mar 17 02:38:51 2026 -0700
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.net>
CommitDate: Tue Mar 17 10:48:28 2026 +0100

    tar: avoid unnecessary VLA
    
    An assignment expression is not a constant expression, so while the
    length of fname is always constant, it becomes a VLA.
    
    The `l` variable never changes, so just use `sizeof fname` for
    clarity.

diff --git a/tar.c b/tar.c
index 4d44ec0..e97662c 100644
--- a/tar.c
+++ b/tar.c
_AT_@ -471,8 +471,8 @@ bad:
 static void
 xt(int argc, char *argv[], int mode)
 {
- long size, l;
- char b[BLKSIZ], fname[l = PATH_MAX + 1], *p, *q = NULL;
+ long size;
+ char b[BLKSIZ], fname[PATH_MAX + 1], *p, *q = NULL;
         int i, m, n;
         int (*fn)(char *, ssize_t, char[BLKSIZ]) = (mode == 'x') ? unarchive : print;
         struct timespec times[2];
_AT_@ -491,7 +491,7 @@ xt(int argc, char *argv[], int mode)
 
                         /* Read header only up to size of fname buffer */
                         for (q = fname; q < fname+size; q += BLKSIZ) {
- if (q + BLKSIZ >= fname + l)
+ if (q + BLKSIZ >= fname + sizeof fname)
                                         eprintf("name exceeds buffer: %.*s\n", q-fname, fname);
                                 eread(tarfd, q, BLKSIZ);
                         }
_AT_@ -518,7 +518,7 @@ xt(int argc, char *argv[], int mode)
                 if (!q) {
                         m = sizeof h->prefix, n = sizeof h->name;
                         p = "/" + !h->prefix[0];
- snprintf(fname, l, "%.*s%s%.*s", m, h->prefix, p, n, h->name);
+ snprintf(fname, sizeof fname, "%.*s%s%.*s", m, h->prefix, p, n, h->name);
                 }
                 q = NULL;
 
Received on Tue Mar 17 2026 - 10:48:43 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 17 2026 - 11:00:40 CET