1 |
|
/* infcover.c -- test zlib's inflate routines with full code coverage |
2 |
< |
* Copyright (C) 2011 Mark Adler |
2 |
> |
* Copyright (C) 2011, 2016 Mark Adler |
3 |
|
* For conditions of distribution and use, see copyright notice in zlib.h |
4 |
|
*/ |
5 |
|
|
237 |
|
|
238 |
|
/* Decode a hexadecimal string, set *len to length, in[] to the bytes. This |
239 |
|
decodes liberally, in that hex digits can be adjacent, in which case two in |
240 |
< |
a row writes a byte. Or they can delimited by any non-hex character, where |
241 |
< |
the delimiters are ignored except when a single hex digit is followed by a |
242 |
< |
delimiter in which case that single digit writes a byte. The returned |
243 |
< |
data is allocated and must eventually be freed. NULL is returned if out of |
244 |
< |
memory. If the length is not needed, then len can be NULL. */ |
240 |
> |
a row writes a byte. Or they can be delimited by any non-hex character, |
241 |
> |
where the delimiters are ignored except when a single hex digit is followed |
242 |
> |
by a delimiter, where that single digit writes a byte. The returned data is |
243 |
> |
allocated and must eventually be freed. NULL is returned if out of memory. |
244 |
> |
If the length is not needed, then len can be NULL. */ |
245 |
|
local unsigned char *h2b(const char *hex, unsigned *len) |
246 |
|
{ |
247 |
< |
unsigned char *in; |
247 |
> |
unsigned char *in, *re; |
248 |
|
unsigned next, val; |
249 |
|
|
250 |
|
in = malloc((strlen(hex) + 1) >> 1); |
268 |
|
} while (*hex++); /* go through the loop with the terminating null */ |
269 |
|
if (len != NULL) |
270 |
|
*len = next; |
271 |
< |
in = reallocf(in, next); |
272 |
< |
return in; |
271 |
> |
re = realloc(in, next); |
272 |
> |
return re == NULL ? in : re; |
273 |
|
} |
274 |
|
|
275 |
|
/* generic inflate() run, where hex is the hexadecimal input data, what is the |