[llvm-commits] [llvm] r138717 - /llvm/trunk/lib/Support/raw_ostream.cpp

Douglas Gregor dgregor at apple.com
Sat Aug 27 22:44:41 PDT 2011


Nice catch, thanks!

Sent from my iPhone

On Aug 27, 2011, at 8:30 PM, Nick Lewycky <nicholas at mxc.ca> wrote:

> Author: nicholas
> Date: Sat Aug 27 22:30:02 2011
> New Revision: 138717
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=138717&view=rev
> Log:
> Fix integer overflow bug in raw_ostream::write. This showed up as a
> non-deterministic crash in the test suite. Fixes PR10055!
> 
> Modified:
>    llvm/trunk/lib/Support/raw_ostream.cpp
> 
> Modified: llvm/trunk/lib/Support/raw_ostream.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=138717&r1=138716&r2=138717&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/raw_ostream.cpp (original)
> +++ llvm/trunk/lib/Support/raw_ostream.cpp Sat Aug 27 22:30:02 2011
> @@ -84,7 +84,7 @@
> }
> 
> void raw_ostream::SetBufferAndMode(char *BufferStart, size_t Size,
> -                                    BufferKind Mode) {
> +                                   BufferKind Mode) {
>   assert(((Mode == Unbuffered && BufferStart == 0 && Size == 0) ||
>           (Mode != Unbuffered && BufferStart && Size)) &&
>          "stream must be unbuffered or have at least one byte");
> @@ -284,7 +284,7 @@
> 
> raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) {
>   // Group exceptional cases into a single branch.
> -  if (BUILTIN_EXPECT(OutBufCur+Size > OutBufEnd, false)) {
> +  if (BUILTIN_EXPECT(size_t(OutBufEnd - OutBufCur) < Size, false)) {
>     if (BUILTIN_EXPECT(!OutBufStart, false)) {
>       if (BufferMode == Unbuffered) {
>         write_impl(Ptr, Size);
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list