]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Prefer intmax_t to size_t in xheader.c
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 2 Nov 2024 06:47:23 +0000 (23:47 -0700)
* src/common.h (INTMAX_STRSIZE_BOUND): New constant.
(SYSINT_BUFSIZE): Use it.
* src/xheader.c (global_header_count, xheader_format_name):
Prefer intmax_t to size_t, as the values are not sizes.

src/common.h
src/xheader.c

index dd1eed7a5e49bc83db6364c656f98c95db9f05a4..29908ce8d598c363a34b740628cd6484beb6d3e1 100644 (file)
@@ -688,9 +688,12 @@ represent_uintmax (uintmax_t n)
     }
 }
 
-enum { UINTMAX_STRSIZE_BOUND = INT_BUFSIZE_BOUND (uintmax_t) };
-enum { SYSINT_BUFSIZE =
-        max (UINTMAX_STRSIZE_BOUND, INT_BUFSIZE_BOUND (intmax_t)) };
+enum
+  {
+    INTMAX_STRSIZE_BOUND = INT_BUFSIZE_BOUND (intmax_t),
+    UINTMAX_STRSIZE_BOUND = INT_BUFSIZE_BOUND (uintmax_t),
+    SYSINT_BUFSIZE = max (INTMAX_STRSIZE_BOUND, UINTMAX_STRSIZE_BOUND)
+  };
 char *sysinttostr (uintmax_t, intmax_t, uintmax_t, char buf[SYSINT_BUFSIZE]);
 intmax_t stoint (char const *, char **, bool *, intmax_t, uintmax_t);
 char *timetostr (time_t, char buf[SYSINT_BUFSIZE]);
@@ -903,7 +906,7 @@ void xheader_string_add (struct xheader *xhdr, char const *s);
 bool xheader_string_end (struct xheader *xhdr, char const *keyword);
 bool xheader_keyword_deleted_p (const char *kw);
 char *xheader_format_name (struct tar_stat_info *st, const char *fmt,
-                          size_t n);
+                          intmax_t n);
 void xheader_xattr_init (struct tar_stat_info *st);
 
 void xattr_map_init (struct xattr_map *map);
index 79d30939b984c3436252425e35c145e049f0a2e3..a3b41e81f329a96a4c6084bfd23a45f055329dfa 100644 (file)
@@ -36,7 +36,7 @@ static void code_string (char const *string, char const *keyword,
                         struct xheader *xhdr);
 
 /* Number of global headers written so far. */
-static size_t global_header_count;
+static intmax_t global_header_count;
 /* FIXME: Possibly it should be reset after changing the volume.
    POSIX %n specification says that it is expanded to the sequence
    number of current global header in *the* archive. However, for
@@ -254,7 +254,7 @@ xheader_set_option (char *string)
      %%                       A '%' character. */
 
 char *
-xheader_format_name (struct tar_stat_info *st, const char *fmt, size_t n)
+xheader_format_name (struct tar_stat_info *st, const char *fmt, intmax_t n)
 {
   char *buf;
   size_t len;
@@ -265,7 +265,7 @@ xheader_format_name (struct tar_stat_info *st, const char *fmt, size_t n)
   char *base = NULL;
   char pidbuf[UINTMAX_STRSIZE_BOUND];
   char const *pptr = NULL;
-  char nbuf[UINTMAX_STRSIZE_BOUND];
+  char nbuf[INTMAX_STRSIZE_BOUND];
   char const *nptr = NULL;
 
   len = 0;
@@ -303,7 +303,7 @@ xheader_format_name (struct tar_stat_info *st, const char *fmt, size_t n)
              break;
 
            case 'n':
-             nptr = umaxtostr (n, nbuf);
+             nptr = imaxtostr (n, nbuf);
              len += nbuf + sizeof nbuf - 1 - nptr;
              break;