Skip to content

Commit 07f2ade

Browse files
authored
bpo-40998: Address compiler warnings found by ubsan (pythonGH-20929)
Signed-off-by: Christian Heimes <christian@python.org> Automerge-Triggered-By: GH:tiran
1 parent 46f59eb commit 07f2ade

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Addressed three compiler warnings found by undefined behavior sanitizer
2+
(ubsan).

Objects/unicodeobject.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,11 @@ xmlcharrefreplace(_PyBytesWriter *writer, char *str,
839839

840840
/* generate replacement */
841841
for (i = collstart; i < collend; ++i) {
842-
str += sprintf(str, "&#%d;", PyUnicode_READ(kind, data, i));
842+
size = sprintf(str, "&#%d;", PyUnicode_READ(kind, data, i));
843+
if (size < 0) {
844+
return NULL;
845+
}
846+
str += size;
843847
}
844848
return str;
845849
}

Parser/string_parser.c

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ decode_unicode_with_escapes(Parser *parser, const char *s, size_t len, Token *t)
6969
return NULL;
7070
}
7171
p = buf = PyBytes_AsString(u);
72+
if (p == NULL) {
73+
return NULL;
74+
}
7275
end = s + len;
7376
while (s < end) {
7477
if (*s == '\\') {

Python/pylifecycle.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,6 @@ Py_FinalizeEx(void)
16441644

16451645
/* Get current thread state and interpreter pointer */
16461646
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
1647-
PyInterpreterState *interp = tstate->interp;
16481647

16491648
// Wrap up existing "threading"-module-created, non-daemon threads.
16501649
wait_for_thread_shutdown(tstate);
@@ -1667,13 +1666,13 @@ Py_FinalizeEx(void)
16671666
/* Copy the core config, PyInterpreterState_Delete() free
16681667
the core config memory */
16691668
#ifdef Py_REF_DEBUG
1670-
int show_ref_count = interp->config.show_ref_count;
1669+
int show_ref_count = tstate->interp->config.show_ref_count;
16711670
#endif
16721671
#ifdef Py_TRACE_REFS
1673-
int dump_refs = interp->config.dump_refs;
1672+
int dump_refs = tstate->interp->config.dump_refs;
16741673
#endif
16751674
#ifdef WITH_PYMALLOC
1676-
int malloc_stats = interp->config.malloc_stats;
1675+
int malloc_stats = tstate->interp->config.malloc_stats;
16771676
#endif
16781677

16791678
/* Remaining daemon threads will automatically exit

0 commit comments

Comments
 (0)