Message 333862 - Python tracker

Message333862

Author vstinner
Recipients David.Edelsohn, cstratak, mark.dickinson, skrah, vstinner
Date 2019-01-17.12:39:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1547728741.81.0.708336517309.issue35752@roundup.psfhosted.org>
In-reply-to
Content
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);
History
Date User Action Args
2019-01-17 12:39:03vstinnersetrecipients: + vstinner, mark.dickinson, skrah, David.Edelsohn, cstratak
2019-01-17 12:39:01vstinnersetmessageid: <1547728741.81.0.708336517309.issue35752@roundup.psfhosted.org>
2019-01-17 12:39:01vstinnerlinkissue35752 messages
2019-01-17 12:39:01vstinnercreate