Skip to content

Commit 6f71e34

Browse files
committed
+1
1 parent 4dc5697 commit 6f71e34

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

Modules/_struct.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ pack_halffloat(_structmodulestate *state,
279279
PyObject *v, /* value to pack */
280280
int le) /* true for little-endian, false for big-endian */
281281
{
282-
double x = PyFloat_AsDouble(v);
282+
volatile double x = PyFloat_AsDouble(v);
283+
283284
if (x == -1.0 && PyErr_Occurred()) {
284285
PyErr_SetString(state->StructError,
285286
"required argument is not a float");
@@ -764,26 +765,28 @@ np_halffloat(_structmodulestate *state, char *p, PyObject *v, const formatdef *f
764765
static int
765766
np_float(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
766767
{
767-
float x = (float)PyFloat_AsDouble(v);
768+
volatile float x = (float)PyFloat_AsDouble(v);
769+
768770
if (x == -1 && PyErr_Occurred()) {
769771
PyErr_SetString(state->StructError,
770772
"required argument is not a float");
771773
return -1;
772774
}
773-
memcpy(p, &x, sizeof x);
775+
memcpy(p, (void *)&x, sizeof x);
774776
return 0;
775777
}
776778

777779
static int
778780
np_double(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
779781
{
780-
double x = PyFloat_AsDouble(v);
782+
volatile double x = PyFloat_AsDouble(v);
783+
781784
if (x == -1 && PyErr_Occurred()) {
782785
PyErr_SetString(state->StructError,
783786
"required argument is not a float");
784787
return -1;
785788
}
786-
memcpy(p, &x, sizeof(double));
789+
memcpy(p, (void *)&x, sizeof(double));
787790
return 0;
788791
}
789792

@@ -1138,7 +1141,8 @@ bp_halffloat(_structmodulestate *state, char *p, PyObject *v, const formatdef *f
11381141
static int
11391142
bp_float(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
11401143
{
1141-
double x = PyFloat_AsDouble(v);
1144+
volatile double x = PyFloat_AsDouble(v);
1145+
11421146
if (x == -1 && PyErr_Occurred()) {
11431147
PyErr_SetString(state->StructError,
11441148
"required argument is not a float");
@@ -1150,7 +1154,8 @@ bp_float(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
11501154
static int
11511155
bp_double(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
11521156
{
1153-
double x = PyFloat_AsDouble(v);
1157+
volatile double x = PyFloat_AsDouble(v);
1158+
11541159
if (x == -1 && PyErr_Occurred()) {
11551160
PyErr_SetString(state->StructError,
11561161
"required argument is not a float");
@@ -1475,7 +1480,8 @@ lp_halffloat(_structmodulestate *state, char *p, PyObject *v, const formatdef *f
14751480
static int
14761481
lp_float(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
14771482
{
1478-
double x = PyFloat_AsDouble(v);
1483+
volatile double x = PyFloat_AsDouble(v);
1484+
14791485
if (x == -1 && PyErr_Occurred()) {
14801486
PyErr_SetString(state->StructError,
14811487
"required argument is not a float");
@@ -1487,7 +1493,8 @@ lp_float(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
14871493
static int
14881494
lp_double(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
14891495
{
1490-
double x = PyFloat_AsDouble(v);
1496+
volatile double x = PyFloat_AsDouble(v);
1497+
14911498
if (x == -1 && PyErr_Occurred()) {
14921499
PyErr_SetString(state->StructError,
14931500
"required argument is not a float");

0 commit comments

Comments
 (0)