From c78dc3bd31f508b497119f23572ed0b771088593 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Thu, 16 Feb 2023 13:10:09 +0000 Subject: [PATCH] Fix a memory bug in StrRandom() with RandIntN(). We're storing integers in this buffer, so we have to allocate enough memory for them. An integer is usually more than one byte. --- src/Str.c | 2 +- tools/bin/td | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Str.c b/src/Str.c index b4172b1..65451fb 100644 --- a/src/Str.c +++ b/src/Str.c @@ -171,7 +171,7 @@ StrRandom(size_t len) return NULL; } - nums = Malloc(len); + nums = Malloc(len * sizeof(int)); if (!nums) { Free(str); diff --git a/tools/bin/td b/tools/bin/td index af9bcdd..0fa9bd2 100644 --- a/tools/bin/td +++ b/tools/bin/td @@ -36,7 +36,7 @@ CFLAGS="${CFLAGS} ${DEFINES} ${INCLUDES}" LDFLAGS="${LDFLAGS} ${STATIC}" if [ "$DEBUG" = "1" ]; then - CFLAGS="$CFLAGS -O0 -g" + CFLAGS="$CFLAGS -O0 -g -pg" LDFLAGS="-lm -pthread -v" PROG="$PROG-debug" fi