Skip to content

Commit 96286f1

Browse files
malon7782gitster
authored andcommitted
symlinks: use unsigned int for flags
The 'flags' and 'track_flags' fields in symlinks.c are used strictly as a collection of bits (using bitwise operators including &, |, ~). Using a signed integer for bitmasks may lead to undefined behavior with shift operations and logic errors if the MSB is touched. Change these fields from 'int' to 'unsigned int' to match our usage patterns. Signed-off-by: Tian Yuchen <a3205153416@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 83a69f1 commit 96286f1

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

symlinks.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ static inline void reset_lstat_cache(struct cache_def *cache)
7474
*/
7575
static int lstat_cache_matchlen(struct cache_def *cache,
7676
const char *name, int len,
77-
int *ret_flags, int track_flags,
77+
unsigned int *ret_flags, unsigned int track_flags,
7878
int prefix_len_stat_func)
7979
{
8080
int match_len, last_slash, last_slash_dir, previous_slash;
81-
int save_flags, ret, saved_errno = 0;
81+
unsigned int save_flags;
82+
int ret, saved_errno = 0;
8283
struct stat st;
8384

8485
if (cache->track_flags != track_flags ||
@@ -192,10 +193,10 @@ static int lstat_cache_matchlen(struct cache_def *cache,
192193
return match_len;
193194
}
194195

195-
static int lstat_cache(struct cache_def *cache, const char *name, int len,
196-
int track_flags, int prefix_len_stat_func)
196+
static unsigned int lstat_cache(struct cache_def *cache, const char *name, int len,
197+
unsigned int track_flags, int prefix_len_stat_func)
197198
{
198-
int flags;
199+
unsigned int flags;
199200
(void)lstat_cache_matchlen(cache, name, len, &flags, track_flags,
200201
prefix_len_stat_func);
201202
return flags;
@@ -234,7 +235,7 @@ int check_leading_path(const char *name, int len, int warn_on_lstat_err)
234235
static int threaded_check_leading_path(struct cache_def *cache, const char *name,
235236
int len, int warn_on_lstat_err)
236237
{
237-
int flags;
238+
unsigned int flags;
238239
int match_len = lstat_cache_matchlen(cache, name, len, &flags,
239240
FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT);
240241
int saved_errno = errno;

symlinks.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
struct cache_def {
77
struct strbuf path;
8-
int flags;
9-
int track_flags;
8+
unsigned int flags;
9+
unsigned int track_flags;
1010
int prefix_len_stat_func;
1111
};
1212
#define CACHE_DEF_INIT { \

0 commit comments

Comments
 (0)