From 30494563f235b21c6583f7476b8ee35e9f5f8048 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sat, 11 Jul 2015 19:14:52 +0200 Subject: basic: util - fix errorhandling in unhexmem() We were ignoring failures from unhexchar, which meant that invalid hex characters were being turned into garbage rather than the string rejected. Fix this by making unhexmem return an error code, also change the API slightly, to return the size of the returned memory, reflecting the fact that the memory is a binary blob,and not a string. For convenience, still append a trailing NULL byte to the returned memory (not included in the returned size), allowing callers to treat it as a string without doing a second copy. --- src/basic/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/basic/util.h') diff --git a/src/basic/util.h b/src/basic/util.h index a1d1dd15c3..ea77907f7f 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -614,7 +614,7 @@ static inline void *mempset(void *s, int c, size_t n) { } char *hexmem(const void *p, size_t l); -void *unhexmem(const char *p, size_t l); +int unhexmem(const char *p, size_t l, void **mem, size_t *len); char *strextend(char **x, ...) _sentinel_; char *strrep(const char *s, unsigned n); -- cgit v1.2.3-54-g00ecf