Skip to content

KRandom::randomString: properly cast from char to QChar

str[i++] = char(r); does not do what one expects: due to QT_NO_CAST_FROM_ASCII QCharRef &operator=(char c) is not available, so the compiler goes for implicit cast from char to int and calls QCharRef &operator=(int rc) instead. Reason is that there is no char-overload declared as private QCharRef member in that case to catch that, unlike other classes.

Current code does not trigger any issue though, thus the unexpected code path got unnoticed.

@aacid

In case you are curious, add this to the QCharRef class declaration:

private:
#ifdef QT_NO_CAST_FROM_ASCII
    QCharRef &operator=(char c);
    QCharRef &operator=(uchar c);
#endif

Seems this got forgotten to be added to catch the unwanted calls, other than in QString & Co. PS: Looking for someone to propose that patch for Qt.. no resources to do myself.

Update: Qt issue filed as https://bugreports.qt.io/browse/QTBUG-88431

Edited by Friedrich W. H. Kossebau

Merge request reports