2015-07-30 17:18 GMT+03:00 Vadim Ushakov <[email protected]>:
> Hi,
>
> According to the manpage, the escape sequence \nnn is expanded to the
> octal character nnn in the PS1 prompt.
>
> In fact, it is expanded to a garbage.
>
> It seems that dopprompt() (in src/bin/ksh/lex.c) has the wrong
> calculation:
>
> n = cp[0] * 8 * 8 + cp[1] * 8 + cp[2];
> snprintf(strbuf, sizeof strbuf, "%c", n);
>
> This should probably be:
>
> n = ('0' - cp[0]) * 8 * 8 + ('0' - cp[1]) * 8 + ('0' - cp[2]);
> snprintf(strbuf, sizeof strbuf, "%c", n);

I do acknowledge the report. The corrected fix is below. I don't see
any potential breakage, nothing could rely on previous behaviour.
Thus I'm asking for okay to commit.

Too bad that I don't know how to make a test for this issue in
regress/usr.bin/ksh, though. It could tests stdin, stdout, stderr and
files, but I dunno how to test the shell prompt. Any ideas?

--
WBR,
  Vadim Zhukov


Index: lex.c
===================================================================
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.49
diff -u -p -r1.49 lex.c
--- lex.c       17 Dec 2013 16:37:06 -0000      1.49
+++ lex.c       30 Jul 2015 14:39:42 -0000
@@ -1370,7 +1370,8 @@ dopprompt(const char *sp, int ntruncate,
                                            "\\%c", *cp);
                                        break;
                                }
-                               n = cp[0] * 8 * 8 + cp[1] * 8 + cp[2];
+                               n = (cp[0] - '0') * 8 * 8 + (cp[1] - '0') * 8 +
+                                   (cp[2] - '0');
                                snprintf(strbuf, sizeof strbuf, "%c", n);
                                cp += 2;
                                break;

Reply via email to