From 6a70ad85340b25b5e3a224d61e4cee7277333969 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 6 Nov 2013 14:13:06 -0500 Subject: cppcheck and Coverity cleanup (not yet complete). All regression tests pass. PPS is live. --- hex.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'hex.c') diff --git a/hex.c b/hex.c index 95f4121d..ac1705f3 100644 --- a/hex.c +++ b/hex.c @@ -87,20 +87,22 @@ static int hex2bin(const char *s) int gpsd_hexpack( /*@in@*/ const char *src, /*@out@ */ char *dst, size_t len) /* hex2bin source string to destination - destination can be same as source */ { - int i, k, l; + int i, j; /*@ -mustdefine @*/ - l = (int)(strlen(src) / 2); - if ((l < 1) || ((size_t) l > len)) + j = (int)(strlen(src) / 2); + if ((j < 1) || ((size_t) j > len)) return -2; - for (i = 0; i < l; i++) + for (i = 0; i < j; i++) { + int k; if ((k = hex2bin(src + i * 2)) != -1) dst[i] = (char)(k & 0xff); else return -1; + } (void)memset(dst + i, '\0', (size_t) (len - i)); - return l; + return j; /*@ +mustdefine @*/ } -- cgit v1.2.1