diff options
author | snaury <snaury@ydb.tech> | 2023-08-02 16:31:12 +0300 |
---|---|---|
committer | snaury <snaury@ydb.tech> | 2023-08-02 16:31:12 +0300 |
commit | f8a265e9e38423af909b4a7223b90d7c0bce51dc (patch) | |
tree | bd3f40c2cd1d7d9d9ae440a921791098c1b42656 | |
parent | c0ca04d62a4ae68bf09193c3a9941d28bf343028 (diff) | |
download | ydb-f8a265e9e38423af909b4a7223b90d7c0bce51dc.tar.gz |
Fix some ubsan failures in erasure tests KIKIMR-18923
-rw-r--r-- | ydb/core/erasure/erasure_perf_test.cpp | 5 | ||||
-rw-r--r-- | ydb/core/erasure/ut_util.h | 17 |
2 files changed, 13 insertions, 9 deletions
diff --git a/ydb/core/erasure/erasure_perf_test.cpp b/ydb/core/erasure/erasure_perf_test.cpp index 79965e9bdeb..5983da63560 100644 --- a/ydb/core/erasure/erasure_perf_test.cpp +++ b/ydb/core/erasure/erasure_perf_test.cpp @@ -101,7 +101,10 @@ std::pair<double, double> MeasureTime(TErasureType &type, TVector<ui32> &missedP for (ui32 i = 0; i < type.TotalPartCount(); ++i) { auto data = partSet.Parts[i].OwnedString.GetContiguousSpan(); TString newOwnedString(partSize, '\0'); - memcpy(newOwnedString.Detach(), data.data(), data.size()); + if (data.size() > 0) { + Y_VERIFY(partSize >= data.size()); + memcpy(newOwnedString.Detach(), data.data(), data.size()); + } partSet.Parts[i].ReferenceTo(partSet.Parts[i].OwnedString); } } diff --git a/ydb/core/erasure/ut_util.h b/ydb/core/erasure/ut_util.h index ef2f7236553..4f994158a11 100644 --- a/ydb/core/erasure/ut_util.h +++ b/ydb/core/erasure/ut_util.h @@ -5,6 +5,7 @@ #include <util/random/mersenne64.h> #include <util/stream/null.h> #include <util/string/printf.h> +#include <util/system/unaligned_mem.h> IOutputStream& Ctest = Cnull; @@ -56,15 +57,15 @@ inline void GenNextCombination(ui32 *variants, ui32 const k, ui32 const n) { inline TString GenerateRandomString(NPrivate::TMersenne64 &randGen, size_t dataSize) { TString testString; testString.resize(dataSize); - char *writePosChar = (char *)testString.data(); - ui32 charParts = testString.size() % sizeof(ui64); - for (ui32 i = 0; i < charParts; ++i) { - writePosChar[i] = (char)randGen.GenRand(); + char *p = testString.Detach(); + while (dataSize >= sizeof(ui64)) { + WriteUnaligned<ui64>(p, randGen.GenRand()); + p += sizeof(ui64); + dataSize -= sizeof(ui64); } - ui64 *writePos64 = (ui64 *)writePosChar; - ui32 ui64Parts = testString.size() / sizeof(ui64); - for (ui32 i = 0; i < ui64Parts; ++i) { - writePos64[i] = randGen.GenRand(); + while (dataSize > 0) { + *p++ = (char)randGen.GenRand(); + --dataSize; } return testString; } |