Skip to content
This repository was archived by the owner on Jul 5, 2023. It is now read-only.

Commit f72d7f3

Browse files
ddfishergvanrossum
authored andcommitted
Fix parsing of old style octals in ast27 (#28)
Fixes #26.
1 parent 1ddc368 commit f72d7f3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ast27/Python/ast.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,6 +3500,7 @@ parsenumber(struct compiling *c, const char *s)
35003500
const char *end;
35013501
long x;
35023502
double dx;
3503+
int old_style_octal;
35033504
#ifndef WITHOUT_COMPLEX
35043505
Py_complex complex;
35053506
int imflag;
@@ -3519,14 +3520,17 @@ parsenumber(struct compiling *c, const char *s)
35193520
return PyErr_NoMemory();
35203521
memcpy(copy, s, len);
35213522
copy[len - 1] = '\0';
3522-
PyObject *result = PyLong_FromString(copy, (char **)0, 0);
3523+
old_style_octal = len > 2 && copy[0] == '0' && copy[1] >= '0' && copy[1] <= '9';
3524+
PyObject *result = PyLong_FromString(copy, (char **)0, old_style_octal ? 8 : 0);
35233525
free(copy);
35243526
return result;
35253527
}
35263528
x = Ta27OS_strtol((char *)s, (char **)&end, 0);
35273529
if (*end == '\0') {
3528-
if (errno != 0)
3529-
return PyLong_FromString((char *)s, (char **)0, 0);
3530+
if (errno != 0) {
3531+
old_style_octal = end - s > 1 && s[0] == '0' && s[1] >= '0' && s[1] <= '9';
3532+
return PyLong_FromString((char *)s, (char **)0, old_style_octal ? 8 : 0);
3533+
}
35303534
return PyLong_FromLong(x);
35313535
}
35323536
/* XXX Huge floats may silently fail */

0 commit comments

Comments
 (0)