Skip to content

Commit 791d7fa

Browse files
Seija KijinAZero13
authored andcommitted
git: use U to denote unsigned to prevent UB
1 << can be UB if 1 ends up overflowing and being assigned to an unsigned int or long. Signed-off-by: Seija Kijin <[email protected]>
1 parent 063bceb commit 791d7fa

File tree

12 files changed

+23
-23
lines changed

12 files changed

+23
-23
lines changed

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static int check_stages(unsigned stages, const struct cache_entry *ce, int pos)
223223
ce = the_repository->index->cache[pos];
224224
if (strcmp(name, ce->name))
225225
break;
226-
seen |= (1 << ce_stage(ce));
226+
seen |= (1U << ce_stage(ce));
227227
pos++;
228228
}
229229
if ((stages & seen) != stages)

builtin/merge-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ static void unresolved(const struct traverse_info *info, struct name_entry n[3])
270270
unsigned dirmask = 0, mask = 0;
271271

272272
for (i = 0; i < 3; i++) {
273-
mask |= (1 << i);
273+
mask |= (1U << i);
274274
/*
275275
* Treat missing entries as directories so that we return
276276
* after unresolved_directory has handled this.
277277
*/
278278
if (!n[i].mode || S_ISDIR(n[i].mode))
279-
dirmask |= (1 << i);
279+
dirmask |= (1U << i);
280280
}
281281

282282
unresolved_directory(info, n);

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
13061306
struct shallow_lock shallow_lock = SHALLOW_LOCK_INIT;
13071307
struct oid_array extra = OID_ARRAY_INIT;
13081308
struct check_connected_options opt = CHECK_CONNECTED_INIT;
1309-
uint32_t mask = 1 << (cmd->index % 32);
1309+
uint32_t mask = 1U << (cmd->index % 32);
13101310
int i;
13111311

13121312
trace_printf_key(&trace_shallow,

color.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ int color_parse_mem(const char *value, int value_len, char *dst)
317317
}
318318
val = parse_attr(word, wordlen);
319319
if (0 <= val)
320-
attr |= (1 << val);
320+
attr |= (1U << val);
321321
else
322322
goto bad;
323323
}
@@ -340,7 +340,7 @@ int color_parse_mem(const char *value, int value_len, char *dst)
340340
sep++;
341341

342342
for (i = 0; attr; i++) {
343-
unsigned bit = (1 << i);
343+
unsigned bit = (1U << i);
344344
if (!(attr & bit))
345345
continue;
346346
attr &= ~bit;

delta-islands.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static int island_bitmap_is_subset(struct island_bitmap *self,
7878
}
7979

8080
#define ISLAND_BITMAP_BLOCK(x) (x / 32)
81-
#define ISLAND_BITMAP_MASK(x) (1 << (x % 32))
81+
#define ISLAND_BITMAP_MASK(x) (1U << (x % 32))
8282

8383
static void island_bitmap_set(struct island_bitmap *self, uint32_t i)
8484
{

diff-delta.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
156156
}
157157
hsize = entries / 4;
158158
for (i = 4; (1u << i) < hsize; i++);
159-
hsize = 1 << i;
159+
hsize = 1u << i;
160160
hmask = hsize - 1;
161161

162162
/* allocate lookup index */

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4815,7 +4815,7 @@ static void prepare_filter_bits(void)
48154815

48164816
if (!filter_bit[DIFF_STATUS_ADDED]) {
48174817
for (i = 0; diff_status_letters[i]; i++)
4818-
filter_bit[(int) diff_status_letters[i]] = (1 << i);
4818+
filter_bit[(int) diff_status_letters[i]] = (1U << i);
48194819
}
48204820
}
48214821

help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ void list_cmds_by_category(struct string_list *list,
394394

395395
for (i = 0; category_names[i]; i++) {
396396
if (!strcmp(cat, category_names[i])) {
397-
cat_id = 1UL << i;
397+
cat_id = 1U << i;
398398
break;
399399
}
400400
}

imap-send.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ static void parse_capability(struct imap *imap, char *cmd)
644644
while ((arg = next_arg(&cmd)))
645645
for (i = 0; i < ARRAY_SIZE(cap_list); i++)
646646
if (!strcmp(cap_list[i], arg))
647-
imap->caps |= 1 << i;
647+
imap->caps |= 1U << i;
648648
imap->rcaps = imap->caps;
649649
}
650650

merge-ort.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ static void collect_rename_info(struct merge_options *opt,
12181218
return;
12191219

12201220
for (side = MERGE_SIDE1; side <= MERGE_SIDE2; ++side) {
1221-
unsigned side_mask = (1 << side);
1221+
unsigned side_mask = (1U << side);
12221222

12231223
/* Check for deletion on side */
12241224
if ((filemask & 1) && !(filemask & side_mask))
@@ -2026,7 +2026,7 @@ static void initialize_attr_index(struct merge_options *opt)
20262026

20272027
ASSIGN_AND_VERIFY_CI(ci, mi);
20282028
for (stage = 0; stage < 3; stage++) {
2029-
unsigned stage_mask = (1 << stage);
2029+
unsigned stage_mask = (1U << stage);
20302030

20312031
if (!(ci->filemask & stage_mask))
20322032
continue;
@@ -2362,7 +2362,7 @@ static char *handle_path_level_conflicts(struct merge_options *opt,
23622362
*/
23632363
if (c_info->reported_already) {
23642364
clean = 0;
2365-
} else if (path_in_way(&opt->priv->paths, new_path, 1 << side_index)) {
2365+
} else if (path_in_way(&opt->priv->paths, new_path, 1U << side_index)) {
23662366
c_info->reported_already = 1;
23672367
strbuf_add_separated_string_list(&collision_paths, ", ",
23682368
&c_info->source_files);
@@ -2747,7 +2747,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
27472747
ci->filemask = 0;
27482748
ci->merged.clean = 1;
27492749
for (i = MERGE_BASE; i <= MERGE_SIDE2; i++) {
2750-
if (ci->dirmask & (1 << i))
2750+
if (ci->dirmask & (1U << i))
27512751
continue;
27522752
/* zero out any entries related to files */
27532753
ci->stages[i].mode = 0;
@@ -2915,7 +2915,7 @@ static int process_renames(struct merge_options *opt,
29152915
assert(side1 == side2);
29162916
memcpy(&side1->stages[0], &base->stages[0],
29172917
sizeof(merged));
2918-
side1->filemask |= (1 << MERGE_BASE);
2918+
side1->filemask |= (1U << MERGE_BASE);
29192919
/* Mark base as resolved by removal */
29202920
base->merged.is_null = 1;
29212921
base->merged.clean = 1;
@@ -3002,7 +3002,7 @@ static int process_renames(struct merge_options *opt,
30023002
target_index = pair->score; /* from collect_renames() */
30033003
assert(target_index == 1 || target_index == 2);
30043004
other_source_index = 3 - target_index;
3005-
old_sidemask = (1 << other_source_index); /* 2 or 4 */
3005+
old_sidemask = (1U << other_source_index); /* 2 or 4 */
30063006
source_deleted = (oldinfo->filemask == 1);
30073007
collision = ((newinfo->filemask & old_sidemask) != 0);
30083008
type_changed = !source_deleted &&
@@ -3116,7 +3116,7 @@ static int process_renames(struct merge_options *opt,
31163116
*/
31173117
memcpy(&newinfo->stages[0], &oldinfo->stages[0],
31183118
sizeof(newinfo->stages[0]));
3119-
newinfo->filemask |= (1 << MERGE_BASE);
3119+
newinfo->filemask |= (1U << MERGE_BASE);
31203120
newinfo->pathnames[0] = oldpath;
31213121
if (type_changed) {
31223122
/* rename vs. typechange */
@@ -3139,7 +3139,7 @@ static int process_renames(struct merge_options *opt,
31393139
memcpy(&newinfo->stages[other_source_index],
31403140
&oldinfo->stages[other_source_index],
31413141
sizeof(newinfo->stages[0]));
3142-
newinfo->filemask |= (1 << other_source_index);
3142+
newinfo->filemask |= (1U << other_source_index);
31433143
newinfo->pathnames[other_source_index] = oldpath;
31443144
}
31453145
}
@@ -3990,7 +3990,7 @@ static int process_entry(struct merge_options *opt,
39903990
ci->match_mask = (ci->match_mask & ~ci->dirmask);
39913991
ci->dirmask = 0;
39923992
for (i = MERGE_BASE; i <= MERGE_SIDE2; i++) {
3993-
if (ci->filemask & (1 << i))
3993+
if (ci->filemask & (1U << i))
39943994
continue;
39953995
ci->stages[i].mode = 0;
39963996
oidcpy(&ci->stages[i].oid, null_oid());

0 commit comments

Comments
 (0)