8000 gh-70278: Fix PyUnicode_FromFormat() with precision for %s and %V by serhiy-storchaka · Pull Request #120365 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-70278: Fix PyUnico 8000 de_FromFormat() with precision for %s and %V #120365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a comment and refactor.
  • Loading branch information
serhiy-storchaka committed Jun 12, 2024
commit 4000cdfd192fd9a32e29a120581bfbc79da03019
13 changes: 9 additions & 4 deletions Objects/unicodeobject.c
8DC6
Original file line numberDiff line number Diff line change
Expand Up @@ -2389,19 +2389,24 @@ unicode_fromformat_write_utf8(_PyUnicodeWriter *writer, const char *str,
Py_ssize_t width, Py_ssize_t precision, int flags)
{
/* UTF-8 */
Py_ssize_t *pconsumed = NULL;
Py_ssize_t length;
Py_ssize_t consumed;
Py_ssize_t *pconsumed;
if (precision == -1) {
length = strlen(str);
pconsumed = NULL;
}
else {
length = 0;
while (length < precision && str[length]) {
length++;
}
pconsumed = (length < precision) ? NULL : &consumed;
if (length == precision) {
/* The input string is not NUL-terminated. If it ends with an
* incomplete UTF-8 sequence, truncate the string just before it.
* Incomplete sequences in the middle and sequences which cannot
* be valid prefixes are still treated as errors and replaced
* with \xfffd. */
pconsumed = &length;
}
}

if (width < 0) {
Expand Down
0