[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,
llvm-svn: 371219
diff --git a/MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c b/MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c
index d6e7f1e..9f968fc 100644
--- a/MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c
+++ b/MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c
@@ -349,7 +349,7 @@
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));