tools/gf_poly.c: fix undefined allocation of 0 bytes
Due to man page of malloc the behaviour in case of allocation size of 0 bytes is undefined: "If size was equal to 0, either NULL or a pointer suitable to be passed to free() is returned" Fix for clang scan-build report: Unix API Undefined allocation of 0 bytes (CERT MEM04-C; CWE-131) 210 poly = (gf_general_t *) malloc(sizeof(gf_general_t)*(n+1)); 9 Call to 'malloc' has an allocation size of 0 bytes Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>master
parent
f6936562b2
commit
3e242830b0
|
@ -52,6 +52,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
char *BM = "Bad Method: ";
|
char *BM = "Bad Method: ";
|
||||||
|
|
||||||
|
@ -203,9 +204,14 @@ int main(int argc, char **argv)
|
||||||
sprintf(string, "Argument '%s' not in proper format of power:coefficient\n", argv[i]);
|
sprintf(string, "Argument '%s' not in proper format of power:coefficient\n", argv[i]);
|
||||||
usage(string);
|
usage(string);
|
||||||
}
|
}
|
||||||
if (power < 0) usage("Can't have negative powers\n");
|
if (power < 0) {
|
||||||
if (power > n) n = power;
|
usage("Can't have negative powers\n");
|
||||||
|
} else {
|
||||||
|
n = power;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// in case the for-loop header fails
|
||||||
|
assert (n >= 0);
|
||||||
|
|
||||||
poly = (gf_general_t *) malloc(sizeof(gf_general_t)*(n+1));
|
poly = (gf_general_t *) malloc(sizeof(gf_general_t)*(n+1));
|
||||||
for (i = 0; i <= n; i++) gf_general_set_zero(poly+i, w);
|
for (i = 0; i <= n; i++) gf_general_set_zero(poly+i, w);
|
||||||
|
|
Loading…
Reference in New Issue