Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd85c3a

Browse files
author
Victor Stinner
committed
fill_number() and format_string_internal() check for PyUnicode_CopyCharacters() failure
1 parent dba2dee commit fd85c3a

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Python/formatter_unicode.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,10 @@ fill_number(PyObject *out, Py_ssize_t pos, const NumberFieldWidths *spec,
566566
PyUnicode_WRITE(kind, data, pos++, spec->sign);
567567
}
568568
if (spec->n_prefix) {
569-
PyUnicode_CopyCharacters(out, pos, prefix, p_start, spec->n_prefix);
569+
if (PyUnicode_CopyCharacters(out, pos,
570+
prefix, p_start,
571+
spec->n_prefix) < 0)
572+
return -1;
570573
if (toupper) {
571574
Py_ssize_t t;
572575
/* XXX if the upper-case prefix is wider than the target
@@ -632,7 +635,8 @@ fill_number(PyObject *out, Py_ssize_t pos, const NumberFieldWidths *spec,
632635
}
633636

634637
if (spec->n_remainder) {
635-
PyUnicode_CopyCharacters(out, pos, digits, d_pos, spec->n_remainder);
638+
if (PyUnicode_CopyCharacters(out, pos, digits, d_pos, spec->n_remainder) < 0)
639+
return -1;
636640
pos += spec->n_remainder;
637641
d_pos += spec->n_remainder;
638642
}
@@ -735,7 +739,8 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format)
735739
lpad, rpad);
736740

737741
/* Then the source string. */
738-
PyUnicode_CopyCharacters(result, pos, value, 0, len);
742+
if (PyUnicode_CopyCharacters(result, pos, value, 0, len) < 0)
743+
Py_CLEAR(result);
739744

740745
done:
741746
return result;

0 commit comments

Comments
 (0)