From 7eb4a67ae7250af4dd174452419f25023c46068f Mon Sep 17 00:00:00 2001 From: Shauren Date: Wed, 26 Apr 2023 00:19:36 +0200 Subject: Core/DataStores: Changed empty string checks in db2 loaders to not rely on undefined behavior (comparing pointers to different objects/arrays with greater/less) --- src/common/DataStores/DB2FileLoader.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/common/DataStores/DB2FileLoader.cpp') diff --git a/src/common/DataStores/DB2FileLoader.cpp b/src/common/DataStores/DB2FileLoader.cpp index b57f475890a..e72c8ff23fb 100644 --- a/src/common/DataStores/DB2FileLoader.cpp +++ b/src/common/DataStores/DB2FileLoader.cpp @@ -597,23 +597,13 @@ char* DB2FileLoaderRegularImpl::AutoProduceStrings(char** indexTable, uint32 ind offset += 8; break; case FT_STRING: - { - char const* string = RecordGetString(rawRecord, x, z); - if (string >= reinterpret_cast(_stringTable)) // ensure string is inside _stringTable - reinterpret_cast(&recordData[offset])->Str[locale] = stringPool + (string - reinterpret_cast(_stringTable)); - + reinterpret_cast(&recordData[offset])->Str[locale] = stringPool + (RecordGetString(rawRecord, x, z) - reinterpret_cast(_stringTable)); offset += sizeof(LocalizedString); break; - } case FT_STRING_NOT_LOCALIZED: - { - char const* string = RecordGetString(rawRecord, x, z); - if (string >= reinterpret_cast(_stringTable)) // ensure string is inside _stringTable - *reinterpret_cast(&recordData[offset]) = stringPool + (string - reinterpret_cast(_stringTable)); - + *reinterpret_cast(&recordData[offset]) = stringPool + (RecordGetString(rawRecord, x, z) - reinterpret_cast(_stringTable)); offset += sizeof(char*); break; - } default: ABORT_MSG("Unknown format character '%c' found in %s meta for field %s", _loadInfo->Fields[fieldIndex].Type, _fileName, _loadInfo->Fields[fieldIndex].Name); @@ -810,7 +800,7 @@ char const* DB2FileLoaderRegularImpl::RecordGetString(uint8 const* record, uint3 uint32 fieldOffset = GetFieldOffset(field) + sizeof(uint32) * arrayIndex; uint32 stringOffset = RecordGetVarInt(record, field, arrayIndex); ASSERT(stringOffset < _header->RecordSize * _header->RecordCount + _header->StringTableSize); - return reinterpret_cast(record + fieldOffset + stringOffset); + return stringOffset ? reinterpret_cast(record + fieldOffset + stringOffset) : EmptyDb2String; } template -- cgit v1.2.3