Fix potential integer overflows identified by Coverity

Convert ODK_LAST_STRESSABLE_TYPE to an aliased enum value so that
ODK_FieldLength always returns a valid value instead of SIZE_MAX.

PiperOrigin-RevId: 602823670
Change-Id: I7a843cacca8201677c0f31249112c04f6c3e04cb
This commit is contained in:
Googler
2024-01-30 13:26:44 -08:00
committed by Robert Shih
parent b239b11b60
commit e53e8ced89
4 changed files with 7 additions and 9 deletions

View File

@@ -258,7 +258,7 @@ TEST(OdkTest, SerializeFieldsStress) {
size_t total_size = 0;
for (int i = 0; i < n; i++) {
fields[i].type = static_cast<ODK_FieldType>(
std::rand() % static_cast<int>(ODK_LAST_STRESSABLE_TYPE));
std::rand() % (static_cast<int>(ODK_LAST_STRESSABLE_TYPE) + 1));
fields[i].value = malloc(ODK_AllocSize(fields[i].type));
fields[i].name = "stress";
total_size += ODK_FieldLength(fields[i].type);