Skip to content

Commit 825f248

Browse files
georgthegreatwgtmac
authored andcommitted
ORC-1834: [C++] Fix undefined behavior
See #2112 Closes #2116 from georgthegreat/patch-4. Authored-by: Yuriy Chernyshov <[email protected]> Signed-off-by: Gang Wu <[email protected]>
1 parent 6aea9ed commit 825f248

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

c++/src/ColumnReader.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ namespace orc {
395395
int64_t bits = 0;
396396
if (bufferEnd_ - bufferPointer_ >= 8) {
397397
if (isLittleEndian) {
398-
bits = *(reinterpret_cast<const int64_t*>(bufferPointer_));
398+
memcpy(&bits, bufferPointer_, sizeof(bits));
399399
} else {
400400
bits = static_cast<int64_t>(static_cast<unsigned char>(bufferPointer_[0]));
401401
bits |= static_cast<int64_t>(static_cast<unsigned char>(bufferPointer_[1])) << 8;
@@ -509,8 +509,10 @@ namespace orc {
509509
bufferNum = std::min(numValues,
510510
static_cast<size_t>(bufferEnd_ - bufferPointer_) / bytesPerValue_);
511511
uint64_t bufferBytes = bufferNum * bytesPerValue_;
512-
memcpy(outArray, bufferPointer_, bufferBytes);
513-
bufferPointer_ += bufferBytes;
512+
if (bufferBytes > 0) {
513+
memcpy(outArray, bufferPointer_, bufferBytes);
514+
bufferPointer_ += bufferBytes;
515+
}
514516
}
515517
for (size_t i = bufferNum; i < numValues; ++i) {
516518
outArray[i] = readDouble<ValueType>();

0 commit comments

Comments
 (0)