static unsigned char *h2b(const char *hex, unsigned *len) {
unsigned char *in, *re;
unsigned next, val;
+ unsigned inlen;
- in = malloc((strlen(hex) + 1) >> 1);
+ inlen = (strlen(hex) + 1) >> 1;
+ assert(inlen != 0); /* tell static analyzer we won't call malloc(0) */
+ in = malloc(inlen);
if (in == NULL)
return NULL;
next = 0;
} while (*hex++); /* go through the loop with the terminating null */
if (len != NULL)
*len = next;
+ assert(next != 0); /* tell static analyzer we won't call realloc(in, 0) */
re = realloc(in, next);
return re == NULL ? in : re;
}