raw_ostream::operator<<(StringRef): Avoid potential overflow in pointer arithmetic.

(OutBufCur + Size) might overflow if Size were large. For example on i686-linux,

  OutBufCur: 0xFFFDF27D
  OutBufEnd: 0xFFFDF370
  Size:      0x0002BF20 (180,000)

It caused flaky error in MC/COFF/section-name-encoding.s.

llvm-svn: 207621
This commit is contained in:
NAKAMURA Takumi 2014-04-30 09:33:50 +00:00
parent 41cec5c3cb
commit d112b82066
1 changed files with 1 additions and 1 deletions

View File

@ -162,7 +162,7 @@ public:
size_t Size = Str.size();
// Make sure we can use the fast path.
if (OutBufCur+Size > OutBufEnd)
if (Size > (size_t)(OutBufEnd - OutBufCur))
return write(Str.data(), Size);
memcpy(OutBufCur, Str.data(), Size);