Fewer uses of size_t in misc.c
* src/misc.c (assign_string_n, quote_copy_string) (normalize_filename, replace_prefix, remove_any_file) (blocking_read, wd_alloc, wdcache_count, chdir_arg, chdir_do) (read_diag_details, struct namebuf, namebuf_name): Prefer idx_t to size_t.
This commit is contained in:
@@ -636,14 +636,14 @@ void assign_string_or_null (char **dest, const char *src)
|
|||||||
ATTRIBUTE_NONNULL ((1));
|
ATTRIBUTE_NONNULL ((1));
|
||||||
void assign_string (char **dest, const char *src) ATTRIBUTE_NONNULL ((1, 2));
|
void assign_string (char **dest, const char *src) ATTRIBUTE_NONNULL ((1, 2));
|
||||||
void assign_null (char **dest) ATTRIBUTE_NONNULL ((1));
|
void assign_null (char **dest) ATTRIBUTE_NONNULL ((1));
|
||||||
void assign_string_n (char **string, const char *value, size_t n);
|
void assign_string_n (char **string, const char *value, idx_t n);
|
||||||
#define ASSIGN_STRING_N(s,v) assign_string_n (s, v, sizeof (v))
|
#define ASSIGN_STRING_N(s,v) assign_string_n (s, v, sizeof (v))
|
||||||
int unquote_string (char *str);
|
int unquote_string (char *str);
|
||||||
char *zap_slashes (char *name);
|
char *zap_slashes (char *name);
|
||||||
char *normalize_filename (idx_t, char const *);
|
char *normalize_filename (idx_t, char const *);
|
||||||
void normalize_filename_x (char *name);
|
void normalize_filename_x (char *name);
|
||||||
void replace_prefix (char **pname, const char *samp, size_t slen,
|
void replace_prefix (char **pname, const char *samp, idx_t slen,
|
||||||
const char *repl, size_t rlen);
|
const char *repl, idx_t rlen);
|
||||||
char *tar_savedir (const char *name, int must_exist);
|
char *tar_savedir (const char *name, int must_exist);
|
||||||
|
|
||||||
typedef struct namebuf *namebuf_t;
|
typedef struct namebuf *namebuf_t;
|
||||||
@@ -742,7 +742,7 @@ idx_t chdir_count (void);
|
|||||||
|
|
||||||
void close_diag (char const *name);
|
void close_diag (char const *name);
|
||||||
void open_diag (char const *name);
|
void open_diag (char const *name);
|
||||||
void read_diag_details (char const *name, off_t offset, size_t size);
|
void read_diag_details (char const *name, off_t offset, idx_t size);
|
||||||
void readlink_diag (char const *name);
|
void readlink_diag (char const *name);
|
||||||
void savedir_diag (char const *name);
|
void savedir_diag (char const *name);
|
||||||
void seek_diag_details (char const *name, off_t offset);
|
void seek_diag_details (char const *name, off_t offset);
|
||||||
|
|||||||
41
src/misc.c
41
src/misc.c
@@ -68,12 +68,12 @@ assign_null (char **string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
assign_string_n (char **string, const char *value, size_t n)
|
assign_string_n (char **string, const char *value, idx_t n)
|
||||||
{
|
{
|
||||||
free (*string);
|
free (*string);
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
size_t l = strnlen (value, n);
|
idx_t l = strnlen (value, n);
|
||||||
char *p = xmalloc (l + 1);
|
char *p = xmalloc (l + 1);
|
||||||
memcpy (p, value, l);
|
memcpy (p, value, l);
|
||||||
p[l] = 0;
|
p[l] = 0;
|
||||||
@@ -115,7 +115,7 @@ quote_copy_string (const char *string)
|
|||||||
case '\n': case '\\':
|
case '\n': case '\\':
|
||||||
if (!copying)
|
if (!copying)
|
||||||
{
|
{
|
||||||
size_t length = (source - string) - 1;
|
idx_t length = (source - string) - 1;
|
||||||
|
|
||||||
copying = 1;
|
copying = 1;
|
||||||
buffer = xmalloc (length + 2 + 2 * strlen (source) + 1);
|
buffer = xmalloc (length + 2 + 2 * strlen (source) + 1);
|
||||||
@@ -331,7 +331,7 @@ normalize_filename (idx_t cdidx, const char *name)
|
|||||||
should use dev+ino pairs instead of names? (See listed03.at for
|
should use dev+ino pairs instead of names? (See listed03.at for
|
||||||
a related test case.) */
|
a related test case.) */
|
||||||
const char *cdpath = tar_getcdpath (cdidx);
|
const char *cdpath = tar_getcdpath (cdidx);
|
||||||
size_t copylen;
|
idx_t copylen;
|
||||||
bool need_separator;
|
bool need_separator;
|
||||||
|
|
||||||
copylen = strlen (cdpath);
|
copylen = strlen (cdpath);
|
||||||
@@ -351,11 +351,11 @@ normalize_filename (idx_t cdidx, const char *name)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
replace_prefix (char **pname, const char *samp, size_t slen,
|
replace_prefix (char **pname, const char *samp, idx_t slen,
|
||||||
const char *repl, size_t rlen)
|
const char *repl, idx_t rlen)
|
||||||
{
|
{
|
||||||
char *name = *pname;
|
char *name = *pname;
|
||||||
size_t nlen = strlen (name);
|
idx_t nlen = strlen (name);
|
||||||
if (nlen > slen && memcmp (name, samp, slen) == 0 && ISSLASH (name[slen]))
|
if (nlen > slen && memcmp (name, samp, slen) == 0 && ISSLASH (name[slen]))
|
||||||
{
|
{
|
||||||
if (rlen > slen)
|
if (rlen > slen)
|
||||||
@@ -709,7 +709,7 @@ remove_any_file (const char *file_name, enum remove_option option)
|
|||||||
{
|
{
|
||||||
char *directory = tar_savedir (file_name, 0);
|
char *directory = tar_savedir (file_name, 0);
|
||||||
char const *entry;
|
char const *entry;
|
||||||
size_t entrylen;
|
idx_t entrylen;
|
||||||
|
|
||||||
if (! directory)
|
if (! directory)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -847,7 +847,7 @@ deref_stat (char const *name, struct stat *buf)
|
|||||||
ptrdiff_t
|
ptrdiff_t
|
||||||
blocking_read (int fd, void *buf, idx_t count)
|
blocking_read (int fd, void *buf, idx_t count)
|
||||||
{
|
{
|
||||||
size_t bytes = full_read (fd, buf, count);
|
idx_t bytes = full_read (fd, buf, count);
|
||||||
|
|
||||||
#if defined F_SETFL && O_NONBLOCK
|
#if defined F_SETFL && O_NONBLOCK
|
||||||
if (bytes == SAFE_READ_ERROR && errno == EAGAIN)
|
if (bytes == SAFE_READ_ERROR && errno == EAGAIN)
|
||||||
@@ -923,7 +923,7 @@ static struct wd *wd;
|
|||||||
static idx_t wd_count;
|
static idx_t wd_count;
|
||||||
|
|
||||||
/* The allocated size of the vector. */
|
/* The allocated size of the vector. */
|
||||||
static size_t wd_alloc;
|
static idx_t wd_alloc;
|
||||||
|
|
||||||
/* The maximum number of chdir targets with open directories.
|
/* The maximum number of chdir targets with open directories.
|
||||||
Don't make it too large, as many operating systems have a small
|
Don't make it too large, as many operating systems have a small
|
||||||
@@ -936,7 +936,7 @@ enum { CHDIR_CACHE_SIZE = 16 };
|
|||||||
static int wdcache[CHDIR_CACHE_SIZE];
|
static int wdcache[CHDIR_CACHE_SIZE];
|
||||||
|
|
||||||
/* Number of nonzero entries in WDCACHE. */
|
/* Number of nonzero entries in WDCACHE. */
|
||||||
static size_t wdcache_count;
|
static idx_t wdcache_count;
|
||||||
|
|
||||||
idx_t
|
idx_t
|
||||||
chdir_count (void)
|
chdir_count (void)
|
||||||
@@ -951,9 +951,7 @@ chdir_arg (char const *dir)
|
|||||||
{
|
{
|
||||||
if (wd_count == wd_alloc)
|
if (wd_count == wd_alloc)
|
||||||
{
|
{
|
||||||
if (wd_alloc == 0)
|
wd = xpalloc (wd, &wd_alloc, wd_alloc ? 1 : 2, -1, sizeof *wd);
|
||||||
wd_alloc = 2;
|
|
||||||
wd = x2nrealloc (wd, &wd_alloc, sizeof *wd);
|
|
||||||
|
|
||||||
if (! wd_count)
|
if (! wd_count)
|
||||||
{
|
{
|
||||||
@@ -1032,7 +1030,7 @@ chdir_do (idx_t i)
|
|||||||
{
|
{
|
||||||
/* Move the i value to the front of the cache. This is
|
/* Move the i value to the front of the cache. This is
|
||||||
O(CHDIR_CACHE_SIZE), but the cache is small. */
|
O(CHDIR_CACHE_SIZE), but the cache is small. */
|
||||||
size_t ci;
|
idx_t ci;
|
||||||
int prev = wdcache[0];
|
int prev = wdcache[0];
|
||||||
for (ci = 1; prev != i; ci++)
|
for (ci = 1; prev != i; ci++)
|
||||||
{
|
{
|
||||||
@@ -1136,7 +1134,7 @@ open_diag (char const *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
read_diag_details (char const *name, off_t offset, size_t size)
|
read_diag_details (char const *name, off_t offset, idx_t size)
|
||||||
{
|
{
|
||||||
if (ignore_failed_read_option)
|
if (ignore_failed_read_option)
|
||||||
{
|
{
|
||||||
@@ -1232,8 +1230,8 @@ xpipe (int fd[2])
|
|||||||
struct namebuf
|
struct namebuf
|
||||||
{
|
{
|
||||||
char *buffer; /* directory, '/', and directory member */
|
char *buffer; /* directory, '/', and directory member */
|
||||||
size_t buffer_size; /* allocated size of name_buffer */
|
idx_t buffer_size; /* allocated size of name_buffer */
|
||||||
size_t dir_length; /* length of directory part in buffer */
|
idx_t dir_length; /* length of directory part in buffer */
|
||||||
};
|
};
|
||||||
|
|
||||||
namebuf_t
|
namebuf_t
|
||||||
@@ -1259,9 +1257,10 @@ namebuf_free (namebuf_t buf)
|
|||||||
char *
|
char *
|
||||||
namebuf_name (namebuf_t buf, const char *name)
|
namebuf_name (namebuf_t buf, const char *name)
|
||||||
{
|
{
|
||||||
size_t len = strlen (name);
|
idx_t len = strlen (name);
|
||||||
while (buf->dir_length + len + 1 >= buf->buffer_size)
|
ptrdiff_t incr_min = buf->dir_length + len + 2 - buf->buffer_size;
|
||||||
buf->buffer = x2realloc (buf->buffer, &buf->buffer_size);
|
if (0 < incr_min)
|
||||||
|
buf->buffer = xpalloc (buf->buffer, &buf->buffer_size, incr_min, -1, 1);
|
||||||
strcpy (buf->buffer + buf->dir_length, name);
|
strcpy (buf->buffer + buf->dir_length, name);
|
||||||
return buf->buffer;
|
return buf->buffer;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user