All pastes #1428965 Raw Edit

kumbayo

public text v1 · immutable
#1428965 ·published 2009-05-20 17:25 UTC
rendered paste body
From 996a10a2c7a80b443e28327b93785e303db507c2 Mon Sep 17 00:00:00 2001
From: Peter Oberndorfer <snip>
Date: Wed, 20 May 2009 19:22:35 +0200
Subject: [PATCH] fix out of bounds access in TestPool::testNewBlockAllocation()

first all elements of a block are allocated
then one additional element is allocated, which starts a new block
but then memory is written after the end of the first block
which is out of bounds
---
 languages/cpp/parser/tests/test_pool.cpp |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/languages/cpp/parser/tests/test_pool.cpp b/languages/cpp/parser/tests/test_pool.cpp
index 9113221..ba6e5c0 100644
--- a/languages/cpp/parser/tests/test_pool.cpp
+++ b/languages/cpp/parser/tests/test_pool.cpp
@@ -60,10 +60,10 @@ void TestPool::testNewBlockAllocation()
     int lastOne = alloc._S_block_size / sizeof(int) - 1;
     p[lastOne] = 10;
     //the first one in another block
-    alloc.allocate(1);
-    p[lastOne+1] = 11;
+    int *p2 = alloc.allocate(1);
+    p2[0] = 11;
     QCOMPARE(p[lastOne], 10);
-    QCOMPARE(p[lastOne+1], 11);
+    QCOMPARE(p2[0], 11);
 }
 
 void TestPool::testWastedMemoryDueToBlockAllocation()
-- 
1.6.2.3