[issue35752] test_buffer fails on ppc64le: memoryview pack_single() is miscompiled

STINNER Victor report at bugs.python.org
Thu Jan 17 07:39:01 EST 2019


STINNER Victor <vstinner at redhat.com> added the comment:

Extract of memoryview pack_signal() function:

#define PACK_SINGLE(ptr, src, type) \
    do {                                     \
        type x;                              \
        x = (type)src;                       \
        memcpy(ptr, (char *)&x, sizeof x);   \
    } while (0)


    /* floats */
    case 'f': case 'd':
        d = PyFloat_AsDouble(item);
        if (d == -1.0 && PyErr_Occurred())
            goto err_occurred;
        if (fmt[0] == 'f') {
            PACK_SINGLE(ptr, d, float);  // ##### BUG IS HERE ###
        }
        else {
            PACK_SINGLE(ptr, d, double);
        }
        break;

Pseudo-code:

double d = PyFloat_AsDouble(item);
float x;
x = (float)d;
memcpy(ptr, (char *)&x, sizeo x);

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35752>
_______________________________________


More information about the Python-bugs-list mailing list