Skip to content

Commit 9bc0864

Browse files
committed
Finish!
1 parent ade334c commit 9bc0864

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

Modules/_ctypes/_ctypes.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,8 @@ unique_key(CDataObject *target, Py_ssize_t index)
26392639
size_t bytes_left;
26402640

26412641
Py_BUILD_ASSERT(sizeof(string) - 1 > sizeof(Py_ssize_t) * 2);
2642-
cp += sprintf(cp, "%x", Py_SAFE_DOWNCAST(index, Py_ssize_t, int));
2642+
cp += PyOS_snprintf(cp, sizeof(Py_ssize_t), "%x",
2643+
Py_SAFE_DOWNCAST(index, Py_ssize_t, int));
26432644
while (target->b_base) {
26442645
bytes_left = sizeof(string) - (cp - string) - 1;
26452646
/* Hex format needs 2 characters per byte */
@@ -2648,7 +2649,8 @@ unique_key(CDataObject *target, Py_ssize_t index)
26482649
"ctypes object structure too deep");
26492650
return NULL;
26502651
}
2651-
cp += sprintf(cp, ":%x", Py_SAFE_DOWNCAST(target->b_index, Py_ssize_t, int));
2652+
cp += PyOS_snprintf(cp, bytes_left, ":%x",
2653+
Py_SAFE_DOWNCAST(target->b_index, Py_ssize_t, int));
26522654
target = target->b_base;
26532655
}
26542656
return PyUnicode_FromStringAndSize(string, cp-string);

Objects/unicodeobject.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,8 @@ xmlcharrefreplace(_PyBytesWriter *writer, char *str,
733733

734734
/* generate replacement */
735735
for (i = collstart; i < collend; ++i) {
736-
size = sprintf(str, "&#%d;", PyUnicode_READ(kind, data, i));
736+
size = PyOS_snprintf(str, 10, "&#%d;",
737+
PyUnicode_READ(kind, data, i));
737738
if (size < 0) {
738739
return NULL;
739740
}

Parser/string_parser.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ decode_unicode_with_escapes(Parser *parser, const char *s, size_t len, Token *t)
118118
w_len = PyUnicode_GET_LENGTH(w);
119119
for (i = 0; i < w_len; i++) {
120120
Py_UCS4 chr = PyUnicode_READ(kind, data, i);
121-
sprintf(p, "\\U%08x", chr);
121+
PyOS_snprintf(p, 10, "\\U%08x", chr);
122122
p += 10;
123123
}
124124
/* Should be impossible to overflow */

Python/pystrtod.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ format_float_short(double d, char format_code,
12391239
/* Now that we've done zero padding, add an exponent if needed. */
12401240
if (use_exp) {
12411241
*p++ = float_strings[OFS_E][0];
1242-
exp_len = sprintf(p, "%+.02d", exp);
1242+
exp_len = PyOS_snprintf(p, 5, "%+.02d", exp); // see `bufsize` comments
12431243
p += exp_len;
12441244
}
12451245
exit:

0 commit comments

Comments
 (0)