before:
$ env -i PS1='\141' ksh -i</dev/null|vis -clt
\

after:
$ env -i PS1='\141' ksh -i</dev/null|vis -clt
a\

Index: src/bin/ksh/lex.c
===================================================================
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.46
diff -p -u -r1.46 lex.c
--- src/bin/ksh/lex.c   20 Jan 2013 14:47:46 -0000      1.46
+++ src/bin/ksh/lex.c   2 Mar 2013 18:30:06 -0000
@@ -5,8 +5,8 @@
  */
 
 #include "sh.h"
-#include <libgen.h>
 #include <ctype.h>
+#include <libgen.h>
 
 
 /* Structure to keep track of the lexing state and the various pieces of info
@@ -1349,17 +1349,18 @@ dopprompt(const char *sp, int ntruncate,
                        case '4':
                        case '5':
                        case '6':
-                       case '7':
-                               if ((cp[1] > '7' || cp[1] < '0') ||
-                                   (cp[2] > '7' || cp[2] < '0')) {
-                                       snprintf(strbuf, sizeof strbuf,
-                                           "\\%c", *cp);
-                                       break;
-                               }
-                               n = cp[0] * 8 * 8 + cp[1] * 8 + cp[2];
-                               snprintf(strbuf, sizeof strbuf, "%c", n);
-                               cp += 2;
+                       case '7': {
+                               int     i = 3;
+                               char    c = 0;
+
+                               do
+                                       c = (c << 3) + *cp - '0';
+                               while (--i && *++cp >= '0' && *cp <= '7');
+                               cp -= !!i;
+                               strbuf[0] = c;
+                               strbuf[1] = '\0';
                                break;
+                       }
                        case '\\':      /* '\' '\' */
                                strbuf[0] = '\\';
                                strbuf[1] = '\0';

Reply via email to