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.
This commit is contained in:
Paul Eggert
2024-11-01 09:40:36 -07:00
parent c61a2bee73
commit 025f19e6bd
2 changed files with 11 additions and 8 deletions

View 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);

View 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;