File tree Expand file tree Collapse file tree 2 files changed +12
-9
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +12
-9
lines changed
Original file line number Diff line number Diff line change @@ -182,8 +182,11 @@ _testcapi_float_set_snan(PyObject *module, PyObject *obj)
182
182
uint64_t v ;
183
183
memcpy (& v , & d , 8 );
184
184
v &= ~(1ULL << 51 ); /* make sNaN */
185
- memcpy (& d , & v , 8 );
186
- return PyFloat_FromDouble (d );
185
+
186
+ // gh-130317: memcpy() is needed to preserve the sNaN flag on x86 (32-bit)
187
+ PyObject * res = PyFloat_FromDouble (0.0 );
188
+ memcpy (& ((PyFloatObject * )res )-> ob_fval , & v , 8 );
189
+ return res ;
187
190
}
188
191
189
192
static PyMethodDef test_methods [] = {
Original file line number Diff line number Diff line change @@ -2197,12 +2197,10 @@ PyFloat_Pack4(double x, char *data, int le)
2197
2197
2198
2198
memcpy (& v , & x , 8 );
2199
2199
if ((v & (1ULL << 51 )) == 0 ) {
2200
- union float_val {
2201
- float f ;
2202
- uint32_t u32 ;
2203
- } * py = (union float_val * )& y ;
2204
-
2205
- py -> u32 &= ~(1 << 22 ); /* make sNaN */
2200
+ uint32_t u32 ;
2201
+ memcpy (& u32 , & y , 4 );
2202
+ u32 &= ~(1 << 22 ); /* make sNaN */
2203
+ memcpy (& y , & u32 , 4 );
2206
2204
}
2207
2205
}
2208
2206
@@ -2340,7 +2338,9 @@ PyFloat_Pack8(double x, char *data, int le)
2340
2338
return -1 ;
2341
2339
}
2342
2340
else {
2343
- const unsigned char * s = (unsigned char * )& x ;
2341
+ unsigned char as_bytes [8 ];
2342
+ memcpy (as_bytes , & x , 8 );
2343
+ const unsigned char * s = as_bytes ;
2344
2344
int i , incr = 1 ;
2345
2345
2346
2346
if ((double_format == ieee_little_endian_format && !le )
You can’t perform that action at this time.
0 commit comments