chg: use calloc

This commit is contained in:
iceman1001
2019-01-30 21:40:50 +01:00
parent 99b6087b01
commit ad72a424ef
15 changed files with 36 additions and 27 deletions

View File

@@ -377,7 +377,9 @@ ipqx:
/* allocate argument array */
args = argc - optind;
if(!(apolys = malloc(args * sizeof(poly_t)))){
apolys = calloc(args * sizeof(poly_t), sizeof(char));
if ( !apolys ){
uerror("cannot allocate memory for argument list");
return 0;
}

View File

@@ -118,7 +118,7 @@ char * mtostr(const model_t *model) {
+ (checkstr && *checkstr ? strlen(checkstr) : 6)
+ (magicstr && *magicstr ? strlen(magicstr) : 6)
+ (model->name && *model->name ? 2 + strlen(model->name) : 6);
if ((string = malloc(size))) {
if ((string = calloc(size, sizeof(uint8_t)))) {
sprintf(strbuf, "\"%s\"", model->name);
sprintf(string,
"width=%lu "

View File

@@ -349,7 +349,7 @@ pxsubs(const poly_t poly, int flags, int bperhx, unsigned long start, unsigned l
size *= cperhx;
if(!size || ~flags & P_SPACE) ++size; /* for trailing null */
if(!(sptr = string = (char *) malloc(size)))
if(!(sptr = string = (char *) calloc(size, sizeof(char))))
uerror("cannot allocate memory for string");
size = end - start;

View File

@@ -811,7 +811,9 @@ int mbynam(model_t *dest, const char *key) {
if (!aliases->name)
return(-1);
if (!(ukey = malloc((size_t) 1 + strlen(key) + 1))) {
ukey = calloc((size_t) 1 + strlen(key) + 1, sizeof(char));
if (!ukey) {
uerror("[!] cannot allocate memory for comparison string");
return(0);
}
@@ -861,7 +863,9 @@ char * mnames(void) {
++aptr;
}
if (!size) return(NULL);
if ((string = malloc(size))) {
string = calloc(size, sizeof(char));
if (string) {
aptr = aliases;
sptr = string;
while (aptr->name) {

View File

@@ -173,8 +173,9 @@ modpol(const poly_t init, int rflags, int args, const poly_t *argpolys) {
unsigned long alen, blen;
if(args < 2) return(NULL);
if(!(result = malloc(((((args - 1) * args) >> 1) + 1) * sizeof(poly_t))))
result = calloc(((((args - 1) * args) >> 1) + 1) * sizeof(poly_t), sizeof(char));
if(!result)
uerror("cannot allocate memory for codeword table");
rptr = result;
@@ -240,7 +241,8 @@ engini(int *resc, model_t **result, const poly_t divisor, int flags, int args, c
dlen = plen(divisor);
/* Allocate the CRC matrix */
if(!(mat = (poly_t *) malloc((dlen << 1) * sizeof(poly_t))))
mat = (poly_t *) calloc((dlen << 1) * sizeof(poly_t), sizeof(char));
if(!mat)
uerror("cannot allocate memory for CRC matrix");
/* Find arguments of the two shortest lengths */