Do not memleak "copy" in case of an error.
Do not use "sizeof(converted)" in snprintf(), since "converted" is a
"char *" (luckily, 8 >= sizeof(char *)). Also, remove "sizeof(char)"
which is guaranteed to be 1 by the C standard, and replace 8 with 12,
which is enough to hold any stringified int and does not consume more
memory (in both cases, the glibc malloc()ates a minimum-sized chunk).
p += 3;
if (isdigit(*p)){
numsignal = strtol(s,&endp,10);
- if(*endp || endp==s) return NULL; /* not valid */
+ if(*endp || endp==s){ /* not valid */
+ free(copy);
+ return NULL;
+ }
}
if (numsignal){
for (i = 0; i < number_of_signals; i++){
} else {
for (i = 0; i < number_of_signals; i++){
if (strcmp(p, sigtable[i].name) == 0){
- converted = malloc(sizeof(char) * 8);
+ converted = malloc(12);
if (converted)
- snprintf(converted, sizeof(converted) - 1, "%d", sigtable[i].num);
+ snprintf(converted, 12, "%d", sigtable[i].num);
break;
}
}