]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
xar: Do not modify variables in DEBUG block 3027/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 12 May 2026 19:56:11 +0000 (21:56 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 12 May 2026 19:56:11 +0000 (21:56 +0200)
The len variable is used later on. Introduce a new one (debug length) to
limit the amount of characters written to stderr.

Could be further improved with %.*s but let's keep it as simple as
possible, since DEBUG is not default and has to be manually set in
line 89.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libarchive/archive_read_support_format_xar.c

index 874501fc0782739ad87b045f56c748a97f7a03c6..83a4ada6f875b30a0c4f31abb789b7a278e77b42 100644 (file)
@@ -2685,11 +2685,12 @@ xml_data(void *userData, const char *s, size_t len)
 #if DEBUG
        {
                char buff[1024];
-               if (len > (int)(sizeof(buff)-1))
-                       len = (int)(sizeof(buff)-1);
-               strncpy(buff, s, len);
-               buff[len] = 0;
-               fprintf(stderr, "\tlen=%d:\"%s\"\n", len, buff);
+               size_t dlen = len;
+               if (dlen > sizeof(buff) - 1)
+                       dlen = sizeof(buff) - 1;
+               strncpy(buff, s, dlen);
+               buff[dlen] = 0;
+               fprintf(stderr, "\tlen=%zu:\"%s\"\n", dlen, buff);
        }
 #endif
        switch (xar->xmlsts) {