Jacob Garber has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/33850
Change subject: util/cbmem: Use correct integer types for loop indices ......................................................................
util/cbmem: Use correct integer types for loop indices
Make sure that the type of the loop index matches the type of the upper bound. This fixes several -Wsign-compare warnings.
Change-Id: Iaa94ce93bc35d523bc782ad914bfd283606becac Signed-off-by: Jacob Garber jgarber1@ualberta.ca --- M util/cbmem/cbmem.c 1 file changed, 8 insertions(+), 16 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/50/33850/1
diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c index 52fdc9b..9a443a8 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -543,9 +543,7 @@
static const char *timestamp_name(uint32_t id) { - int i; - - for (i = 0; i < ARRAY_SIZE(timestamp_ids); i++) { + for (size_t i = 0; i < ARRAY_SIZE(timestamp_ids); i++) { if (timestamp_ids[i].id == id) return timestamp_ids[i].name; } @@ -608,7 +606,6 @@ /* dump the timestamp table */ static void dump_timestamps(int mach_readable) { - int i; const struct timestamp_table *tst_p; struct timestamp_table *sorted_tst_p; size_t size; @@ -656,7 +653,7 @@ sizeof(struct timestamp_entry), compare_timestamp_entries);
total_time = 0; - for (i = 0; i < sorted_tst_p->num_entries; i++) { + for (uint32_t i = 0; i < sorted_tst_p->num_entries; i++) { uint64_t stamp; const struct timestamp_entry *tse = &sorted_tst_p->entries[i];
@@ -685,7 +682,6 @@ /* dump the tcpa log table */ static void dump_tcpa_log(void) { - int i, j; const struct tcpa_table *tclt_p; size_t size; struct mapping tcpa_mapping; @@ -710,12 +706,12 @@
printf("coreboot TCPA log:\n\n");
- for (i = 0; i < tclt_p->num_entries; i++) { + for (uint16_t i = 0; i < tclt_p->num_entries; i++) { const struct tcpa_entry *tce = &tclt_p->entries[i];
printf(" PCR-%u ", tce->pcr);
- for (j = 0; j < tce->digest_length; j++) + for (uint32_t j = 0; j < tce->digest_length; j++) printf("%02x", tce->digest[j]);
printf(" %s [%s]\n", tce->digest_type, tce->name); @@ -804,9 +800,8 @@ BANNER_REGEX("romstage"), OVERFLOW_REGEX("ramstage"), BANNER_REGEX("ramstage") }; - int i;
- for (i = 0; !cursor && i < ARRAY_SIZE(regex); i++) { + for (size_t i = 0; !cursor && i < ARRAY_SIZE(regex); i++) { regex_t re; regmatch_t match; assert(!regcomp(&re, regex[i], 0)); @@ -873,7 +868,6 @@
void rawdump(uint64_t base, uint64_t size) { - int i; const uint8_t *m; struct mapping dump_mapping;
@@ -881,7 +875,7 @@ if (!m) die("Unable to map rawdump memory\n");
- for (i = 0 ; i < size; i++) + for (uint64_t i = 0 ; i < size; i++) printf("%c", m[i]);
unmap_memory(&dump_mapping); @@ -935,12 +929,11 @@ #define MAX_STAGEx 10 void cbmem_print_entry(int n, uint32_t id, uint64_t base, uint64_t size) { - int i; const char *name; char stage_x[20];
name = NULL; - for (i = 0; i < ARRAY_SIZE(cbmem_ids); i++) { + for (size_t i = 0; i < ARRAY_SIZE(cbmem_ids); i++) { if (cbmem_ids[i].id == id) { name = cbmem_ids[i].name; break; @@ -1388,11 +1381,10 @@
parse_cbtable(baseaddr, cb_table_size); #else - int j; unsigned long long possible_base_addresses[] = { 0, 0xf0000 };
/* Find and parse coreboot table */ - for (j = 0; j < ARRAY_SIZE(possible_base_addresses); j++) { + for (size_t j = 0; j < ARRAY_SIZE(possible_base_addresses); j++) { if (!parse_cbtable(possible_base_addresses[j], 0)) break; }
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33850 )
Change subject: util/cbmem: Use correct integer types for loop indices ......................................................................
Patch Set 1: Code-Review+1
Martin Roth has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33850 )
Change subject: util/cbmem: Use correct integer types for loop indices ......................................................................
Patch Set 1: Code-Review+2
Martin Roth has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/33850 )
Change subject: util/cbmem: Use correct integer types for loop indices ......................................................................
util/cbmem: Use correct integer types for loop indices
Make sure that the type of the loop index matches the type of the upper bound. This fixes several -Wsign-compare warnings.
Change-Id: Iaa94ce93bc35d523bc782ad914bfd283606becac Signed-off-by: Jacob Garber jgarber1@ualberta.ca Reviewed-on: https://review.coreboot.org/c/coreboot/+/33850 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Paul Menzel paulepanter@users.sourceforge.net Reviewed-by: Martin Roth martinroth@google.com --- M util/cbmem/cbmem.c 1 file changed, 8 insertions(+), 16 deletions(-)
Approvals: build bot (Jenkins): Verified Martin Roth: Looks good to me, approved Paul Menzel: Looks good to me, but someone else must approve
diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c index 9d2a643..563bcbe 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -543,9 +543,7 @@
static const char *timestamp_name(uint32_t id) { - int i; - - for (i = 0; i < ARRAY_SIZE(timestamp_ids); i++) { + for (size_t i = 0; i < ARRAY_SIZE(timestamp_ids); i++) { if (timestamp_ids[i].id == id) return timestamp_ids[i].name; } @@ -608,7 +606,6 @@ /* dump the timestamp table */ static void dump_timestamps(int mach_readable) { - int i; const struct timestamp_table *tst_p; struct timestamp_table *sorted_tst_p; size_t size; @@ -656,7 +653,7 @@ sizeof(struct timestamp_entry), compare_timestamp_entries);
total_time = 0; - for (i = 0; i < sorted_tst_p->num_entries; i++) { + for (uint32_t i = 0; i < sorted_tst_p->num_entries; i++) { uint64_t stamp; const struct timestamp_entry *tse = &sorted_tst_p->entries[i];
@@ -685,7 +682,6 @@ /* dump the tcpa log table */ static void dump_tcpa_log(void) { - int i, j; const struct tcpa_table *tclt_p; size_t size; struct mapping tcpa_mapping; @@ -710,12 +706,12 @@
printf("coreboot TCPA log:\n\n");
- for (i = 0; i < tclt_p->num_entries; i++) { + for (uint16_t i = 0; i < tclt_p->num_entries; i++) { const struct tcpa_entry *tce = &tclt_p->entries[i];
printf(" PCR-%u ", tce->pcr);
- for (j = 0; j < tce->digest_length; j++) + for (uint32_t j = 0; j < tce->digest_length; j++) printf("%02x", tce->digest[j]);
printf(" %s [%s]\n", tce->digest_type, tce->name); @@ -806,9 +802,8 @@ BANNER_REGEX("romstage"), OVERFLOW_REGEX("ramstage"), BANNER_REGEX("ramstage") }; - int i;
- for (i = 0; !cursor && i < ARRAY_SIZE(regex); i++) { + for (size_t i = 0; !cursor && i < ARRAY_SIZE(regex); i++) { regex_t re; regmatch_t match; assert(!regcomp(&re, regex[i], 0)); @@ -875,7 +870,6 @@
void rawdump(uint64_t base, uint64_t size) { - int i; const uint8_t *m; struct mapping dump_mapping;
@@ -883,7 +877,7 @@ if (!m) die("Unable to map rawdump memory\n");
- for (i = 0 ; i < size; i++) + for (uint64_t i = 0 ; i < size; i++) printf("%c", m[i]);
unmap_memory(&dump_mapping); @@ -937,12 +931,11 @@ #define MAX_STAGEx 10 void cbmem_print_entry(int n, uint32_t id, uint64_t base, uint64_t size) { - int i; const char *name; char stage_x[20];
name = NULL; - for (i = 0; i < ARRAY_SIZE(cbmem_ids); i++) { + for (size_t i = 0; i < ARRAY_SIZE(cbmem_ids); i++) { if (cbmem_ids[i].id == id) { name = cbmem_ids[i].name; break; @@ -1390,11 +1383,10 @@
parse_cbtable(baseaddr, cb_table_size); #else - int j; unsigned long long possible_base_addresses[] = { 0, 0xf0000 };
/* Find and parse coreboot table */ - for (j = 0; j < ARRAY_SIZE(possible_base_addresses); j++) { + for (size_t j = 0; j < ARRAY_SIZE(possible_base_addresses); j++) { if (!parse_cbtable(possible_base_addresses[j], 0)) break; }