[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gpsd-dev] [PATCH 2/5] gpsd_hexdump: Always dump in hex mode
From: |
chris |
Subject: |
[gpsd-dev] [PATCH 2/5] gpsd_hexdump: Always dump in hex mode |
Date: |
Tue, 5 Jun 2012 17:26:21 +0100 |
From: Christian Gagneraud <address@hidden>
This function doesn't always dump the data in hex form.
The problem is that some users on it to always do hex dumps.
For example, the AIS json code use it to dump undecoded data. Depending on the
data it will have either text dump or hex dump, which breaks the json
idempotency.
* This patch doesn't bring any regression. *
scons check and splint passed
Signed-off-by: Christian Gagneraud <address@hidden>
---
hex.c | 47 ++++++++++++++++++-----------------------------
1 files changed, 18 insertions(+), 29 deletions(-)
diff --git a/hex.c b/hex.c
index ef67f06..0171f7b 100644
--- a/hex.c
+++ b/hex.c
@@ -10,40 +10,29 @@
const char /*@ observer @*/ *gpsd_hexdump(char *binbuf, size_t binbuflen)
{
- char *cp;
- bool printable = true;
-
- assert(binbuf != NULL);
- for (cp = binbuf; cp < binbuf + binbuflen; cp++)
- if (!isprint(*cp) && !isspace(*cp))
- printable = false;
- if (printable)
- return binbuf;
- else {
- static char hexbuf[MAX_PACKET_LENGTH * 2 + 1];
+ 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 @*/
--
1.7.7
- [gpsd-dev] [PATCH 0/5] [AIS] Modifications with potential side effects, chris, 2012/06/05
- [gpsd-dev] [PATCH 5/5] Add script to test for JSON validity, chris, 2012/06/05
- [gpsd-dev] [PATCH 1/5] gpsdecode: honor scale flag, chris, 2012/06/05
- [gpsd-dev] [PATCH 2/5] gpsd_hexdump: Always dump in hex mode,
chris <=
- [gpsd-dev] [PATCH 3/5] json.h: Change JSON_VAL_MAX from 120 to 512, chris, 2012/06/05
- [gpsd-dev] [PATCH 4/5] Add BS talker ID (used by AIS base stations), chris, 2012/06/05
- Re: [gpsd-dev] [PATCH 0/5] [AIS] Modifications with potential side effects, Eric S. Raymond, 2012/06/05