diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-25 18:34:04 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-25 18:34:04 +0000 |
commit | b869a0ade10a150b06b227572f5a19b9037fdde2 (patch) | |
tree | c9dc936805e97fb5f48bc4db96746e655f43fee3 /llvm/lib/Support/APInt.cpp | |
parent | 3ad60b18cb4567f1e2c971c900dfad4c7476afed (diff) | |
download | bcm5719-llvm-b869a0ade10a150b06b227572f5a19b9037fdde2.tar.gz bcm5719-llvm-b869a0ade10a150b06b227572f5a19b9037fdde2.zip |
Fix PR4040: APInt's string constructor is too strict
patch by Jeff Yasskin!
llvm-svn: 70058
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 1cabe0f03e7..8ac589c865f 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -1918,9 +1918,9 @@ void APInt::fromString(unsigned numbits, const char *str, unsigned slen, if (isNeg) str++, slen--; assert((slen <= numbits || radix != 2) && "Insufficient bit width"); - assert((slen*3 <= numbits || radix != 8) && "Insufficient bit width"); - assert((slen*4 <= numbits || radix != 16) && "Insufficient bit width"); - assert(((slen*64)/22 <= numbits || radix != 10) && "Insufficient bit width"); + assert(((slen-1)*3 <= numbits || radix != 8) && "Insufficient bit width"); + assert(((slen-1)*4 <= numbits || radix != 16) && "Insufficient bit width"); + assert((((slen-1)*64)/22 <= numbits || radix != 10) && "Insufficient bit width"); // Allocate memory if (!isSingleWord()) @@ -1961,10 +1961,12 @@ void APInt::fromString(unsigned numbits, const char *str, unsigned slen, } // Shift or multiply the value by the radix - if (shift) - *this <<= shift; - else - *this *= apradix; + if (slen > 1) { + if (shift) + *this <<= shift; + else + *this *= apradix; + } // Add in the digit we just interpreted if (apdigit.isSingleWord()) |