summaryrefslogtreecommitdiffstats
path: root/Modules/main.c
diff options
context:
space:
mode:
authorPhilip Jenvey <pjenvey@underboss.org>2010-04-10 20:27:15 (GMT)
committerPhilip Jenvey <pjenvey@underboss.org>2010-04-10 20:27:15 (GMT)
commitcdd98fb4634f6d3fc0815bfe490e1076e8b6ee9e (patch)
tree0d6ef2e5a7e942c10b17007547b687a1e20bdd45 /Modules/main.c
parentb60ee469cd1cd9c51f319fc32fa37987581605d1 (diff)
downloadcpython-cdd98fb4634f6d3fc0815bfe490e1076e8b6ee9e.zip
cpython-cdd98fb4634f6d3fc0815bfe490e1076e8b6ee9e.tar.gz
cpython-cdd98fb4634f6d3fc0815bfe490e1076e8b6ee9e.tar.bz2
fix PYTHONWARNINGS handling to not modify the original env value and improve
its tests
Diffstat (limited to 'Modules/main.c')
-rw-r--r--Modules/main.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/Modules/main.c b/Modules/main.c
index 0ba01f7..11ac97e 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -421,14 +421,19 @@ Py_Main(int argc, char **argv)
(p = Py_GETENV("PYTHONNOUSERSITE")) && *p != '\0')
Py_NoUserSiteDirectory = 1;
- if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0')
- {
- char* warning = strtok(p, ",");
- while (warning != NULL)
- {
+ if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') {
+ char *buf, *warning;
+
+ buf = (char *)malloc(strlen(p) + 1);
+ if (buf == NULL)
+ Py_FatalError(
+ "not enough memory to copy PYTHONWARNINGS");
+ strcpy(buf, p);
+ for (warning = strtok(buf, ",");
+ warning != NULL;
+ warning = strtok(NULL, ","))
PySys_AddWarnOption(warning);
- warning = strtok(NULL, ",");
- }
+ free(buf);
}
if (command == NULL && module == NULL && _PyOS_optind < argc &&