aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorEitan Adler <eadler@FreeBSD.org>2012-01-07 23:15:21 +0000
committerEitan Adler <eadler@FreeBSD.org>2012-01-07 23:15:21 +0000
commit01155b2005d38645ea1fa53f6a43d504fe7111c4 (patch)
tree8390cab5b147ce6b0e32a7801857882296498d36 /usr.bin
parentf5d9d54516d1cbbd27e57fedbbf1205d8af51a1c (diff)
Notes
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/hexdump/parse.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/usr.bin/hexdump/parse.c b/usr.bin/hexdump/parse.c
index 0fa24f5140842..a87eddb15860f 100644
--- a/usr.bin/hexdump/parse.c
+++ b/usr.bin/hexdump/parse.c
@@ -255,7 +255,9 @@ rewrite(FS *fs)
sokay = NOTOKAY;
}
- p2 = p1 + 1; /* Set end pointer. */
+ p2 = *p1 ? p1 + 1 : p1; /* Set end pointer -- make sure
+ * that it's non-NUL/-NULL first
+ * though. */
cs[0] = *p1; /* Set conversion string. */
cs[1] = '\0';
@@ -449,13 +451,21 @@ escape(char *p1)
char *p2;
/* alphabetic escape sequences have to be done in place */
- for (p2 = p1;; ++p1, ++p2) {
- if (!*p1) {
- *p2 = *p1;
- break;
- }
- if (*p1 == '\\')
- switch(*++p1) {
+ for (p2 = p1; *p1; p1++, p2++) {
+ /*
+ * Let's take a peak at the next item and see whether or not
+ * we need to escape the value...
+ */
+ if (*p1 == '\\') {
+
+ p1++;
+
+ switch(*p1) {
+ /* A standalone `\' */
+ case '\0':
+ *p2 = '\\';
+ *++p2 = '\0';
+ break;
case 'a':
/* *p2 = '\a'; */
*p2 = '\007';
@@ -482,7 +492,12 @@ escape(char *p1)
*p2 = *p1;
break;
}
+
+ } else
+ *p2 = *p1;
+
}
+
}
void