From: Paul Eggert Date: Fri, 1 Nov 2024 16:40:36 +0000 (-0700) Subject: Prefer intmax_t to size_t in xheader.c X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=025f19e6bdf1b4f8db536008dc6de7523f9c6607;p=thirdparty%2Ftar.git Prefer intmax_t to size_t in xheader.c * 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. --- diff --git a/src/common.h b/src/common.h index dd1eed7a..29908ce8 100644 --- a/src/common.h +++ b/src/common.h @@ -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); diff --git a/src/xheader.c b/src/xheader.c index 79d30939..a3b41e81 100644 --- a/src/xheader.c +++ b/src/xheader.c @@ -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;