Skip to content

Commit

Permalink
bpo-40998: Address compiler warnings found by ubsan (GH-20929)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Heimes <christian@python.org>

Automerge-Triggered-By: GH:tiran
(cherry picked from commit 07f2ade)

Co-authored-by: Christian Heimes <christian@python.org>
  • Loading branch information
miss-islington and tiran committed Nov 18, 2020
1 parent 802ff7c commit 994c68f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Addressed three compiler warnings found by undefined behavior sanitizer
(ubsan).
6 changes: 5 additions & 1 deletion Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions Parser/pegen/parse_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 == '\\') {
Expand Down
7 changes: 3 additions & 4 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 994c68f

Please sign in to comment.