Skip to content

Commit c4076a1

Browse files
committed
Bug#38439895 Warnings when compiling server in release mode (NDB)
Refactor computeHash function including removing false warning on OEL8 with GCC 14.2.1. storage/ndb/src/ndbapi/Ndb.cpp: In static member function 'static int Ndb::computeHash(Uint32*, const NdbDictionary::Table*, const Key_part_ptr*, void*, Uint32)': storage/ndb/src/ndbapi/Ndb.cpp:489:11: warning: 'buf' may be used uninitialized [-Wmaybe-uninitialized] 489 | md5_hash(values, (const char *)buf, len); | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Change-Id: I39b1b1bdc70ce7487e07d95b7eecb2be963481b1
1 parent fb4f896 commit c4076a1

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

storage/ndb/src/ndbapi/Ndb.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -437,18 +437,11 @@ int Ndb::computeHash(Uint32 *retval, const NdbDictionary::Table *table,
437437
sumlen += len;
438438
}
439439

440-
while (true) {
441-
if (buf == nullptr) {
442-
bufLen = sumlen;
443-
buf = malloc(bufLen);
444-
if (unlikely(buf == nullptr)) return 4000;
445-
malloced_buf = buf; /* Remember to free */
446-
}
447-
assert(bufLen != 0);
448-
449-
if (likely(sumlen <= bufLen)) break;
450-
require(malloced_buf == nullptr);
451-
buf = nullptr;
440+
if (unlikely(buf == nullptr || sumlen > bufLen)) {
441+
bufLen = sumlen;
442+
buf = malloc(bufLen);
443+
if (unlikely(buf == nullptr)) return 4000;
444+
malloced_buf = buf; /* Remember to free */
452445
}
453446

454447
pos = (unsigned char *)buf;
@@ -486,6 +479,8 @@ int Ndb::computeHash(Uint32 *retval, const NdbDictionary::Table *table,
486479
require(len <= bufLen);
487480

488481
Uint32 values[4];
482+
// Avoid maybe-uninitialized warning for md5_hash call
483+
if (unlikely(len == 0)) buf = nullptr;
489484
md5_hash(values, (const char *)buf, len);
490485

491486
if (retval) {

0 commit comments

Comments
 (0)