[C++] Playing with references and types can be hazardous

Well, working on my own Game Engine this week-end, I lost like 5 hours of my life debugging it … and finally, I found that I played with references and types without paying enough attention at it.

inline static bool loadDouble(const QJsonObject& qJsonObject, const char* valueName, quint32& out_int) {
    double d;
    bool res = loadDouble(qJsonObject, valueName, d);
    out_int = d;
    return res;
}

This resulted in writing the end of the d double outside of the out_int quint32.
Simply casting the double solved the overflow.

inline static bool loadDouble(const QJsonObject& qJsonObject, const char* valueName, quint32& out_int) {
    double d;
    bool res = loadDouble(qJsonObject, valueName, d);
    out_int = (quint32)d;
    return res;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s