Skip to content

Commit 2001bba

Browse files
committed
doubletounicode(), longtounicode():
Py_SAFE_DOWNCAST can evaluate its first argument multiple times in a debug build. This caused two distinct assert- failures in test_unicode run under a debug build. Rewrote the code in trivial ways so that multiple evaluation of the first argument doesn't hurt.
1 parent 9ace2be commit 2001bba

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Objects/unicodeobject.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6601,17 +6601,21 @@ strtounicode(Py_UNICODE *buffer, const char *charbuffer)
66016601
static int
66026602
doubletounicode(Py_UNICODE *buffer, size_t len, const char *format, double x)
66036603
{
6604+
Py_ssize_t result;
6605+
66046606
PyOS_ascii_formatd((char *)buffer, len, format, x);
6605-
return Py_SAFE_DOWNCAST(strtounicode(buffer, (char *)buffer),
6606-
Py_ssize_t, int);
6607+
result = strtounicode(buffer, (char *)buffer);
6608+
return Py_SAFE_DOWNCAST(result, Py_ssize_t, int);
66076609
}
66086610

66096611
static int
66106612
longtounicode(Py_UNICODE *buffer, size_t len, const char *format, long x)
66116613
{
6614+
Py_ssize_t result;
6615+
66126616
PyOS_snprintf((char *)buffer, len, format, x);
6613-
return Py_SAFE_DOWNCAST(strtounicode(buffer, (char *)buffer),
6614-
Py_ssize_t, int);
6617+
result = strtounicode(buffer, (char *)buffer);
6618+
return Py_SAFE_DOWNCAST(result, Py_ssize_t, int);
66156619
}
66166620

66176621
/* XXX To save some code duplication, formatfloat/long/int could have been

0 commit comments

Comments
 (0)