From 6449f0917a8bd6f3182a1d5cada13b50843f6a48 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Fri, 6 Sep 2019 16:02:43 +0000 Subject: [MiBench] consumer-typeset: z31: GetMemory(): don't apply offset to nullptr, it's UB Caught by D67122 /repositories/llvm-test-suite/MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c:352:8: runtime error: applying non-zero offset 96 to null pointer #0 0x2e682c in GetMemory (/builddirs/build-test-suite-new/MultiSource/Benchmarks/MiBench/consumer-typeset/consumer-typeset+0x2e682c) #1 0x258c4b in InitFiles (/builddirs/build-test-suite-new/MultiSource/Benchmarks/MiBench/consumer-typeset/consumer-typeset+0x258c4b) #2 0x24d34e in main (/builddirs/build-test-suite-new/MultiSource/Benchmarks/MiBench/consumer-typeset/consumer-typeset+0x24d34e) #3 0x7fe3fb2ac09a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a) #4 0x22e029 in _start (/builddirs/build-test-suite-new/MultiSource/Benchmarks/MiBench/consumer-typeset/consumer-typeset+0x22e029) After that if() the code expects to have enough memory, so the branch should be unconditionally taken if next_free == nullptr, git-svn-id: https://llvm.org/svn/llvm-project/test-suite/trunk@371219 91177308-0d34-0410-b5e6-96231b3b80d8 --- MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c b/MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c index d6e7f1e4..9f968fc7 100644 --- a/MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c +++ b/MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c @@ -349,7 +349,7 @@ OBJECT GetMemory(int siz, FILE_POS *pos) debug1(DMA, DDD, "GetMemory( %d )", siz); /* get memory from operating system, if not enough left here */ - if( &next_free[siz] > top_free ) + if( !next_free || &next_free[siz] > top_free ) { #if DEBUG_ON DebugRegisterUsage(MEM_OBJECTS, 1, MEM_CHUNK * sizeof(ALIGN)); -- cgit v1.2.3