summaryrefslogtreecommitdiff
path: root/hex.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-11-06 14:13:06 -0500
committerEric S. Raymond <esr@thyrsus.com>2013-11-06 14:13:06 -0500
commit6a70ad85340b25b5e3a224d61e4cee7277333969 (patch)
treefa7ec24ea268fb1fd5d6f611b8931320681bb87b /hex.c
parenta7280f885cdc98b06c505a8ea4e4db9bd712ca36 (diff)
downloadgpsd-6a70ad85340b25b5e3a224d61e4cee7277333969.tar.gz
cppcheck and Coverity cleanup (not yet complete).
All regression tests pass. PPS is live.
Diffstat (limited to 'hex.c')
-rw-r--r--hex.c12
1 files changed, 7 insertions, 5 deletions
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 @*/
}