util/romcc: Use 64 bit integers when shifting
'used_indices' is 64 bits wide, so use a fixed-width type to make that clear. As such, 'index' can have a value of up to 63, so use a 64 bit integer when doing the shifts to prevent overflow. Found-by: Coverity Scan CID 1287090 Signed-off-by: Jacob Garber <jgarber1@ualberta.ca> Change-Id: Ibd089df6be60c8ea46da11e5e83cd58b2e2c54d6 Reviewed-on: https://review.coreboot.org/c/coreboot/+/32854 Reviewed-by: Patrick Georgi <pgeorgi@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
1dda496a74
commit
40a85f85c6
|
@ -14111,7 +14111,7 @@ static void compute_closure_variables(struct compile_state *state,
|
||||||
struct block *block;
|
struct block *block;
|
||||||
struct triple *old_result, *first, *ins;
|
struct triple *old_result, *first, *ins;
|
||||||
size_t count, idx;
|
size_t count, idx;
|
||||||
unsigned long used_indices;
|
uint64_t used_indices;
|
||||||
int i, max_index;
|
int i, max_index;
|
||||||
#define MAX_INDICES (sizeof(used_indices)*CHAR_BIT)
|
#define MAX_INDICES (sizeof(used_indices)*CHAR_BIT)
|
||||||
#define ID_BITS(X) ((X) & (TRIPLE_FLAG_LOCAL -1))
|
#define ID_BITS(X) ((X) & (TRIPLE_FLAG_LOCAL -1))
|
||||||
|
@ -14217,11 +14217,11 @@ static void compute_closure_variables(struct compile_state *state,
|
||||||
if (index >= MAX_INDICES) {
|
if (index >= MAX_INDICES) {
|
||||||
internal_error(state, ins, "index unexpectedly large");
|
internal_error(state, ins, "index unexpectedly large");
|
||||||
}
|
}
|
||||||
if (used_indices & (1 << index)) {
|
if (used_indices & ((uint64_t)1 << index)) {
|
||||||
internal_error(state, ins, "index previously used?");
|
internal_error(state, ins, "index previously used?");
|
||||||
}
|
}
|
||||||
/* Remember which indices have been used */
|
/* Remember which indices have been used */
|
||||||
used_indices |= (1 << index);
|
used_indices |= ((uint64_t)1 << index);
|
||||||
if (index > max_index) {
|
if (index > max_index) {
|
||||||
max_index = index;
|
max_index = index;
|
||||||
}
|
}
|
||||||
|
@ -14249,7 +14249,7 @@ static void compute_closure_variables(struct compile_state *state,
|
||||||
}
|
}
|
||||||
info[ID_BITS(ins->id)].index = index;
|
info[ID_BITS(ins->id)].index = index;
|
||||||
/* Remember which indices have been used */
|
/* Remember which indices have been used */
|
||||||
used_indices |= (1 << index);
|
used_indices |= ((uint64_t)1 << index);
|
||||||
if (index > max_index) {
|
if (index > max_index) {
|
||||||
max_index = index;
|
max_index = index;
|
||||||
}
|
}
|
||||||
|
@ -14263,7 +14263,7 @@ static void compute_closure_variables(struct compile_state *state,
|
||||||
for(i = 0; i <= max_index; i++) {
|
for(i = 0; i <= max_index; i++) {
|
||||||
struct triple *var;
|
struct triple *var;
|
||||||
var = 0;
|
var = 0;
|
||||||
if (used_indices & (1 << i)) {
|
if (used_indices & ((uint64_t)1 << i)) {
|
||||||
for(set = vars; set; set = set->next) {
|
for(set = vars; set; set = set->next) {
|
||||||
int index;
|
int index;
|
||||||
index = info[ID_BITS(set->member->id)].index;
|
index = info[ID_BITS(set->member->id)].index;
|
||||||
|
|
Loading…
Reference in New Issue