From d42fdd0b273b2c849ed12bb49536d29a18601626 Mon Sep 17 00:00:00 2001 From: Ruiling Song Date: Tue, 24 Sep 2013 15:39:36 +0800 Subject: [PATCH] GBE: Fix a constant bug which over-write memory. Previously it will always write 8 byte no matter what size of integer. Fix it by only copying necessary data. Reported by Homer Hsing. Signed-off-by: Ruiling Song Reviewed-by: Zhigang Gong --- backend/src/llvm/llvm_gen_backend.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp index 5284ce5..224c971 100644 --- a/backend/src/llvm/llvm_gen_backend.cpp +++ b/backend/src/llvm/llvm_gen_backend.cpp @@ -631,8 +631,10 @@ namespace gbe case Type::TypeID::IntegerTyID: { const ConstantInt *ci = dyn_cast(c); - *(uint64_t *)((char*)mem + offset) = ci->isNegative() ? ci->getSExtValue() : ci->getZExtValue(); - offset += ci->getBitWidth() / 8; + uint32_t size = ci->getBitWidth() / 8; + uint64_t data = ci->isNegative() ? ci->getSExtValue() : ci->getZExtValue(); + memcpy((char*)mem+offset, &data, size); + offset += size; break; } case Type::TypeID::FloatTyID: -- 2.7.4