bpo-29714: Fix a regression that bytes format may fail when containing zero bytes inside. (GH-499)

This commit is contained in:
Xiang Zhang 2017-03-06 17:17:05 +08:00 committed by GitHub
parent 86aa269646
commit b76ad5121e
3 changed files with 15 additions and 2 deletions

View file

@ -619,11 +619,11 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
Py_ssize_t len;
char *pos;
pos = strchr(fmt + 1, '%');
pos = (char *)memchr(fmt + 1, '%', fmtcnt);
if (pos != NULL)
len = pos - fmt;
else
len = format_len - (fmt - format);
len = fmtcnt + 1;
assert(len != 0);
memcpy(res, fmt, len);