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>
Tian Yuchen committed
Feb 17, 2026 at 01:20 UTC
96286f14b0dc1a1c9ba4f6842d99ce738cc766da
2 files changed
+9
-8
symlinks.c
+7
-6
@@ -74,11 +74,12 @@ static inline void reset_lstat_cache(struct cache_def *cache)
74
*/
75
static int lstat_cache_matchlen(struct cache_def *cache,
76
const char *name, int len,
77
- int *ret_flags, int track_flags,
77
+ unsigned int *ret_flags, unsigned int track_flags,
78
int prefix_len_stat_func)
79
{
80
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;
83
struct stat st;
84
85
if (cache->track_flags != track_flags ||
@@ -192,10 +193,10 @@ static int lstat_cache_matchlen(struct cache_def *cache,
193
return match_len;
194
}
195
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)
198
{
198
- int flags;
199
+ unsigned int flags;
200
(void)lstat_cache_matchlen(cache, name, len, &flags, track_flags,
201
prefix_len_stat_func);
202
return flags;
@@ -234,7 +235,7 @@ int check_leading_path(const char *name, int len, int warn_on_lstat_err)
235
static int threaded_check_leading_path(struct cache_def *cache, const char *name,
236
int len, int warn_on_lstat_err)
237
{
237
- int flags;
238
+ unsigned int flags;
239
int match_len = lstat_cache_matchlen(cache, name, len, &flags,
240
FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT);
241
int saved_errno = errno;
symlinks.h
+2
-2
@@ -5,8 +5,8 @@
5
6
struct cache_def {
7
struct strbuf path;
8
- int flags;
9
- int track_flags;
8
+ unsigned int flags;
9
+ unsigned int track_flags;
10
int prefix_len_stat_func;
11
};
12
#define CACHE_DEF_INIT { \