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

Fix parsing of old style octals in ast27 #28

Merged
merged 1 commit into from
Jan 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions ast27/Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -3500,6 +3500,7 @@ parsenumber(struct compiling *c, const char *s)
const char *end;
long x;
double dx;
int old_style_octal;
#ifndef WITHOUT_COMPLEX
Py_complex complex;
int imflag;
Expand All @@ -3519,14 +3520,17 @@ parsenumber(struct compiling *c, const char *s)
return PyErr_NoMemory();
memcpy(copy, s, len);
copy[len - 1] = '\0';
PyObject *result = PyLong_FromString(copy, (char **)0, 0);
old_style_octal = len > 2 && copy[0] == '0' && copy[1] >= '0' && copy[1] <= '9';
PyObject *result = PyLong_FromString(copy, (char **)0, old_style_octal ? 8 : 0);
free(copy);
return result;
}
x = Ta27OS_strtol((char *)s, (char **)&end, 0);
if (*end == '\0') {
if (errno != 0)
return PyLong_FromString((char *)s, (char **)0, 0);
if (errno != 0) {
old_style_octal = end - s > 1 && s[0] == '0' && s[1] >= '0' && s[1] <= '9';
return PyLong_FromString((char *)s, (char **)0, old_style_octal ? 8 : 0);
}
return PyLong_FromLong(x);
}
/* XXX Huge floats may silently fail */
Expand Down