[Python-checkins] bpo-40998: Address compiler warnings found by ubsan (GH-20929)
miss-islington
webhook-mailer at python.org
Wed Nov 18 11:01:58 EST 2020
https://github.com/python/cpython/commit/994c68f586441cee755508e9357e6e03e2b7a887
commit: 994c68f586441cee755508e9357e6e03e2b7a887
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2020-11-18T08:01:48-08:00
summary:
bpo-40998: Address compiler warnings found by ubsan (GH-20929)
Signed-off-by: Christian Heimes <christian at python.org>
Automerge-Triggered-By: GH:tiran
(cherry picked from commit 07f2adedf0940b06d136208ec386d69b7d2d5b43)
Co-authored-by: Christian Heimes <christian at python.org>
files:
A Misc/NEWS.d/next/Build/2020-06-17-09-05-02.bpo-40998.sgqmg9.rst
M Objects/unicodeobject.c
M Parser/pegen/parse_string.c
M Python/pylifecycle.c
diff --git a/Misc/NEWS.d/next/Build/2020-06-17-09-05-02.bpo-40998.sgqmg9.rst b/Misc/NEWS.d/next/Build/2020-06-17-09-05-02.bpo-40998.sgqmg9.rst
new file mode 100644
index 0000000000000..c268e4fd0d9cb
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2020-06-17-09-05-02.bpo-40998.sgqmg9.rst
@@ -0,0 +1,2 @@
+Addressed three compiler warnings found by undefined behavior sanitizer
+(ubsan).
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index ea359039528b6..ffd13f7dd3892 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -847,7 +847,11 @@ xmlcharrefreplace(_PyBytesWriter *writer, char *str,
/* generate replacement */
for (i = collstart; i < collend; ++i) {
- str += sprintf(str, "&#%d;", PyUnicode_READ(kind, data, i));
+ size = sprintf(str, "&#%d;", PyUnicode_READ(kind, data, i));
+ if (size < 0) {
+ return NULL;
+ }
+ str += size;
}
return str;
}
diff --git a/Parser/pegen/parse_string.c b/Parser/pegen/parse_string.c
index 7b02bdde645e8..fb0c4aff9d3d0 100644
--- a/Parser/pegen/parse_string.c
+++ b/Parser/pegen/parse_string.c
@@ -74,6 +74,9 @@ decode_unicode_with_escapes(Parser *parser, const char *s, size_t len, Token *t)
return NULL;
}
p = buf = PyBytes_AsString(u);
+ if (p == NULL) {
+ return NULL;
+ }
end = s + len;
while (s < end) {
if (*s == '\\') {
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 5c50d4d290f4d..60f091cbbea14 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1353,7 +1353,6 @@ Py_FinalizeEx(void)
/* Get current thread state and interpreter pointer */
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
- PyInterpreterState *interp = tstate->interp;
// Wrap up existing "threading"-module-created, non-daemon threads.
wait_for_thread_shutdown(tstate);
@@ -1376,13 +1375,13 @@ Py_FinalizeEx(void)
/* Copy the core config, PyInterpreterState_Delete() free
the core config memory */
#ifdef Py_REF_DEBUG
- int show_ref_count = interp->config.show_ref_count;
+ int show_ref_count = tstate->interp->config.show_ref_count;
#endif
#ifdef Py_TRACE_REFS
- int dump_refs = interp->config.dump_refs;
+ int dump_refs = tstate->interp->config.dump_refs;
#endif
#ifdef WITH_PYMALLOC
- int malloc_stats = interp->config.malloc_stats;
+ int malloc_stats = tstate->interp->config.malloc_stats;
#endif
/* Remaining daemon threads will automatically exit
More information about the Python-checkins
mailing list