Supress malloc warning using gcc 8

Explicitly prevents malloc with negative number to supress -Walloc-size-larger-than
Fixes #168 reported by Ian Jeffray
This commit is contained in:
Robin Stuart 2019-10-30 07:46:36 +00:00
parent 03d99ceb23
commit 7bcc0252a9

View File

@ -49,7 +49,7 @@
// size. // size.
#include <stdio.h> // only needed for debug (main) #include <stdio.h> // only needed for debug (main)
#include <stdlib.h> // only needed for malloc/free #include <malloc.h>
#include "reedsol.h" #include "reedsol.h"
static int logmod; // 2**symsize - 1 static int logmod; // 2**symsize - 1
static int rlen; static int rlen;
@ -75,6 +75,11 @@ void rs_init_gf(const int poly) {
b >>= 1; b >>= 1;
m--; m--;
// Ensure m not negative to supress gcc -Walloc-size-larger-than
if (m < 0) {
m = 0;
}
// Calculate the log/alog tables // Calculate the log/alog tables
logmod = (1 << m) - 1; logmod = (1 << m) - 1;
logt = (int *) malloc(sizeof (int) * (logmod + 1)); logt = (int *) malloc(sizeof (int) * (logmod + 1));