summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hex.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/hex.c b/hex.c
index 04eae847..991673ff 100644
--- a/hex.c
+++ b/hex.c
@@ -4,12 +4,20 @@
*/
#include <string.h>
#include <ctype.h>
+#include <assert.h>
#include "gpsd.h"
char /*@ observer @*/ *gpsd_hexdump(char *binbuf, size_t binbuflen)
{
- if (isprint(binbuf[binbuflen-1]))
+ 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];