On Sat, 2 Mar 2013, [email protected] wrote:
> --- 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>
Not sure what this has to do with anything...
> - 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;
> + }
Hmm, this is actually changing two things: it's both fixing the problem
that the code is not subtracting '0' from each character before doing the
octal place conversion and it's also changing it to support octal
sequences of fewer than 3 digits. The latter seems unnecessary and isn't
documented, do we really need/want to add it?
If not, the fix for the "missing '0' subtraction" is just a two line
change:
@@ -1356,7 +1356,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;
Philip Guenther