[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/6] canonicalize: prefer signed integer types
From: |
Paul Eggert |
Subject: |
[PATCH 5/6] canonicalize: prefer signed integer types |
Date: |
Wed, 2 Dec 2020 14:39:45 -0800 |
* lib/canonicalize.c: Include stddef.h, for ptrdiff_t.
(seen_triple, canonicalize_filename_mode): Prefer signed to
unsigned types where either will do, as they avoid some glitches
in comparisons and can trap on overflow when debugging.
---
ChangeLog | 6 ++++++
lib/canonicalize.c | 21 +++++++++++----------
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a2af24dc4..625bae737 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2020-12-02 Paul Eggert <eggert@cs.ucla.edu>
+ canonicalize: prefer signed integer types
+ * lib/canonicalize.c: Include stddef.h, for ptrdiff_t.
+ (seen_triple, canonicalize_filename_mode): Prefer signed to
+ unsigned types where either will do, as they avoid some glitches
+ in comparisons and can trap on overflow when debugging.
+
canonicalize: fix most of another EOVERFLOW issue
* lib/canonicalize.c (canonicalize_filename_mode):
Do not call stat if fewer than 20 symlinks have been traversed.
diff --git a/lib/canonicalize.c b/lib/canonicalize.c
index 2618844e8..e363cfef3 100644
--- a/lib/canonicalize.c
+++ b/lib/canonicalize.c
@@ -19,6 +19,7 @@
#include "canonicalize.h"
#include <errno.h>
+#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
@@ -71,7 +72,7 @@ seen_triple (Hash_table **ht, char const *filename, struct
stat const *st)
{
if (*ht == NULL)
{
- size_t initial_capacity = 7;
+ int initial_capacity = 7;
*ht = hash_initialize (initial_capacity,
NULL,
triple_hash,
@@ -102,13 +103,13 @@ canonicalize_filename_mode (const char *name,
canonicalize_mode_t can_mode)
char const *start;
char const *end;
char const *rname_limit;
- size_t extra_len = 0;
+ ptrdiff_t extra_len = 0;
Hash_table *ht = NULL;
int saved_errno;
int can_flags = can_mode & ~CAN_MODE_MASK;
bool logical = can_flags & CAN_NOLINKS;
int num_links = 0;
- size_t prefix_len;
+ ptrdiff_t prefix_len;
can_mode &= CAN_MODE_MASK;
@@ -139,8 +140,8 @@ canonicalize_filename_mode (const char *name,
canonicalize_mode_t can_mode)
rname = xgetcwd ();
if (!rname)
return NULL;
- size_t rnamelen = strlen (rname);
- size_t rnamesize = rnamelen; /* Lower bound on size; good enough. */
+ ptrdiff_t rnamelen = strlen (rname);
+ ptrdiff_t rnamesize = rnamelen; /* Lower bound on size; good enough. */
if (rnamesize < PATH_MAX)
{
rnamesize = PATH_MAX;
@@ -172,7 +173,7 @@ canonicalize_filename_mode (const char *name,
canonicalize_mode_t can_mode)
/* For UNC file names '\\server\path\to\file', extend the prefix
to include the server: '\\server\'. */
{
- size_t i;
+ ptrdiff_t i;
for (i = 2; name[i] != '\0' && !ISSLASH (name[i]); )
i++;
if (name[i] != '\0' /* implies ISSLASH (name[i]) */
@@ -227,7 +228,7 @@ canonicalize_filename_mode (const char *name,
canonicalize_mode_t can_mode)
if (rname_limit - dest <= end - start)
{
ptrdiff_t dest_offset = dest - rname;
- size_t new_size = rname_limit - rname;
+ ptrdiff_t new_size = rname_limit - rname;
if (end - start + 1 > PATH_MAX)
new_size += end - start + 1;
@@ -283,8 +284,8 @@ canonicalize_filename_mode (const char *name,
canonicalize_mode_t can_mode)
}
}
- size_t n = strlen (buf);
- size_t len = strlen (end);
+ ptrdiff_t n = strlen (buf);
+ ptrdiff_t len = strlen (end);
if (!extra_len)
{
@@ -304,7 +305,7 @@ canonicalize_filename_mode (const char *name,
canonicalize_mode_t can_mode)
if (IS_ABSOLUTE_FILE_NAME (buf))
{
- size_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf);
+ ptrdiff_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf);
if (pfxlen)
memcpy (rname, buf, pfxlen);
--
2.27.0
[PATCH 6/6] canonicalize: refactor can_mode flag, Paul Eggert, 2020/12/02
[PATCH 5/6] canonicalize: prefer signed integer types,
Paul Eggert <=
Re: [PATCH 1/6] canonicalize-lgpl: fix EOVERFLOW bug, Adhemerval Zanella, 2020/12/11
- Re: [PATCH 1/6] canonicalize-lgpl: fix EOVERFLOW bug, Paul Eggert, 2020/12/17
- Re: [PATCH 1/6] canonicalize-lgpl: fix EOVERFLOW bug, Adhemerval Zanella, 2020/12/18
- Re: [PATCH 1/6] canonicalize-lgpl: fix EOVERFLOW bug, Adhemerval Zanella, 2020/12/18
- Re: [PATCH 1/6] canonicalize-lgpl: fix EOVERFLOW bug, Paul Eggert, 2020/12/18
- Re: [PATCH 1/6] canonicalize-lgpl: fix EOVERFLOW bug, Paul Eggert, 2020/12/24
- Re: [PATCH 1/6] canonicalize-lgpl: fix EOVERFLOW bug, Tom G. Christensen, 2020/12/31