diff options
Diffstat (limited to 'hex.c')
-rw-r--r-- | hex.c | 47 |
1 files changed, 26 insertions, 21 deletions
@@ -8,7 +8,7 @@ #include "gpsd.h" -const char /*@ observer @*/ *gpsd_hexdump(char *binbuf, size_t binbuflen) +const char /*@ observer @*/ *gpsd_packetdump(char *binbuf, size_t binbuflen) { char *cp; bool printable = true; @@ -19,31 +19,36 @@ const char /*@ observer @*/ *gpsd_hexdump(char *binbuf, size_t binbuflen) printable = false; if (printable) return binbuf; - else { - static char hexbuf[MAX_PACKET_LENGTH * 2 + 1]; + else + return gpsd_hexdump(binbuf, binbuflen); +} + +const char /*@ observer @*/ *gpsd_hexdump(char *binbuf, size_t binbuflen) +{ + /* FIXME: this isn't thead-safe! */ + static char hexbuf[MAX_PACKET_LENGTH * 2 + 1]; #ifndef SQUELCH_ENABLE - size_t i, j = 0; - size_t len = - (size_t) ((binbuflen > - MAX_PACKET_LENGTH) ? MAX_PACKET_LENGTH : binbuflen); - const char *ibuf = (const char *)binbuf; - const char *hexchar = "0123456789abcdef"; + size_t i, j = 0; + size_t len = + (size_t) ((binbuflen > + MAX_PACKET_LENGTH) ? MAX_PACKET_LENGTH : binbuflen); + const char *ibuf = (const char *)binbuf; + const char *hexchar = "0123456789abcdef"; - if (NULL == binbuf || 0 == binbuflen) - return ""; + if (NULL == binbuf || 0 == binbuflen) + return ""; - /*@ -shiftimplementation @*/ - for (i = 0; i < len; i++) { - hexbuf[j++] = hexchar[(ibuf[i] & 0xf0) >> 4]; - hexbuf[j++] = hexchar[ibuf[i] & 0x0f]; - } - /*@ +shiftimplementation @*/ - hexbuf[j] = '\0'; + /*@ -shiftimplementation @*/ + for (i = 0; i < len; i++) { + hexbuf[j++] = hexchar[(ibuf[i] & 0xf0) >> 4]; + hexbuf[j++] = hexchar[ibuf[i] & 0x0f]; + } + /*@ +shiftimplementation @*/ + hexbuf[j] = '\0'; #else /* SQUELCH defined */ - hexbuf[0] = '\0'; + hexbuf[0] = '\0'; #endif /* SQUELCH_ENABLE */ - return hexbuf; - } + return hexbuf; } /*@ +charint -shiftimplementation @*/ |