Merge pull request #50 from jtraglia/check-fscanf-ret-value

Check fscanf return value
This commit is contained in:
Ramana Kumar 2022-12-21 20:21:29 +00:00 committed by GitHub
commit de91ee1bbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 6 deletions

View File

@ -810,20 +810,27 @@ C_KZG_RET load_trusted_setup(KZGSettings *out, const uint8_t g1_bytes[], size_t
C_KZG_RET load_trusted_setup_file(KZGSettings *out, FILE *in) { C_KZG_RET load_trusted_setup_file(KZGSettings *out, FILE *in) {
uint64_t i; uint64_t i;
int num_matches;
fscanf(in, "%" SCNu64, &i); num_matches = fscanf(in, "%" SCNu64, &i);
CHECK(num_matches == 1);
CHECK(i == FIELD_ELEMENTS_PER_BLOB); CHECK(i == FIELD_ELEMENTS_PER_BLOB);
fscanf(in, "%" SCNu64, &i); num_matches = fscanf(in, "%" SCNu64, &i);
CHECK(num_matches == 1);
CHECK(i == 65); CHECK(i == 65);
uint8_t g1_bytes[FIELD_ELEMENTS_PER_BLOB * 48]; uint8_t g1_bytes[FIELD_ELEMENTS_PER_BLOB * 48];
uint8_t g2_bytes[65 * 96]; uint8_t g2_bytes[65 * 96];
for (i = 0; i < FIELD_ELEMENTS_PER_BLOB * 48; i++) for (i = 0; i < FIELD_ELEMENTS_PER_BLOB * 48; i++) {
fscanf(in, "%2hhx", &g1_bytes[i]); num_matches = fscanf(in, "%2hhx", &g1_bytes[i]);
CHECK(num_matches == 1);
}
for (i = 0; i < 65 * 96; i++) for (i = 0; i < 65 * 96; i++) {
fscanf(in, "%2hhx", &g2_bytes[i]); num_matches = fscanf(in, "%2hhx", &g2_bytes[i]);
CHECK(num_matches == 1);
}
return load_trusted_setup(out, g1_bytes, FIELD_ELEMENTS_PER_BLOB, g2_bytes, 65); return load_trusted_setup(out, g1_bytes, FIELD_ELEMENTS_PER_BLOB, g2_bytes, 65);
} }