[PATCH] D20755: [MC] Check the upper bound in truncate assertion

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Fri May 27 14:57:43 PDT 2016


phosek created this revision.
phosek added a reviewer: rafael.
phosek added subscribers: rafael, phosek, llvm-commits.
phosek set the repository for this revision to rL LLVM.

The truncateToSize function already has assertion to check the
lower boundary for the number bytes, but it does not check the
upper boundary which could still lead to usage errors.

Repository:
  rL LLVM

http://reviews.llvm.org/D20755

Files:
  lib/MC/MCAsmStreamer.cpp

Index: lib/MC/MCAsmStreamer.cpp
===================================================================
--- lib/MC/MCAsmStreamer.cpp
+++ lib/MC/MCAsmStreamer.cpp
@@ -303,7 +303,7 @@
 }
 
 static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
-  assert(Bytes && "Invalid size!");
+  assert(Bytes > 0 && Bytes <= 8 && "Invalid size!");
   return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20755.58845.patch
Type: text/x-patch
Size: 416 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160527/42dcbee3/attachment.bin>


More information about the llvm-commits mailing list