Diff between b5a8f0b30560d26e65b32152f0b96d8b68645fe2 and c9729d61215382eee43340ad937c2239ac3e8e6f

Changed Files

File Additions Deletions Status
tools/parser/sdp.c +17 -8 modified

Full Patch

diff --git a/tools/parser/sdp.c b/tools/parser/sdp.c
index 3f0d120..73b62ca 100644
--- a/tools/parser/sdp.c
+++ b/tools/parser/sdp.c
@@ -28,6 +28,7 @@
 
 #include <stdio.h>
 #include <errno.h>
+#include <ctype.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
@@ -359,16 +360,24 @@ static inline void print_uuid(int n, struct frame *frm, uint16_t *psm, uint8_t *
 
 static inline void print_string(int n, struct frame *frm, const char *name)
 {
-	char *s;
+	int i, hex = 0;
+
+	for (i = 0; i < n; i++)
+		if (!isprint(((char *) frm->ptr)[i])) {
+			hex = 1;
+			break;
+		}
 
 	printf(" %s", name);
-	if ((s = malloc(n + 1))) {
-		strncpy(s, frm->ptr, n);
-		s[n] = '\0';
-		printf(" \"%s\"", s);
-		free(s);
-	} else
-		perror("Can't allocate string buffer");
+	if (hex) {
+		for (i = 0; i < n; i++)
+			printf(" %02x", ((unsigned char *) frm->ptr)[i]);
+	} else {
+		printf(" \"");
+		for (i = 0; i < n; i++)
+			printf("%c", ((char *) frm->ptr)[i]);
+		printf("\"");
+	}
 
 	frm->ptr += n;
 	frm->len -= n;