Changeset 229 for trunk/src/corelib


Ignore:
Timestamp:
Oct 16, 2009, 1:19:40 AM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: QSettings [Win, OS/2]: When setting and then getting string or binary data, a destructive Latin1 -> QString -> Local8Bit -> QString -> Latin1 conversion could be performed replacing characters >0x7F with '?' in the stream. As a result, saving e.g. a QDateTime object and then reading it could construct a completely different one [nasty vendor bug].

Location:
trunk/src/corelib/io
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/corelib/io/qsettings_os2.cpp

    r63 r229  
    677677    }
    678678
     679
     680
     681
     682
     683
     684
     685
     686
    679687    switch (dataType) {
    680688        case REG_EXPAND_SZ:
     
    685693                    s = QString::fromUtf16(((const ushort*)data.constData()));
    686694                }, {
    687                     s = QString::fromLocal8Bit(data.constData());
     695                    s = QString::fromL(data.constData());
    688696                } );
    689697            }
     
    723731                    s = QString::fromUtf16((const ushort*)data.constData(), data.size()/2);
    724732                }, {
    725                     s = QString::fromLocal8Bit(data.constData(), data.size());
     733                    s = QString::fromL(data.constData(), data.size());
    726734                } );
    727735            }
     
    876884    QByteArray regValueBuff;
    877885
     886
     887
     888
     889
     890
     891
     892
     893
    878894    // Determine the type
    879895    switch (value.type()) {
     
    897913                    regValueBuff = QByteArray((const char*)s.utf16(), s.length()*2);
    898914                }, {
    899                     regValueBuff = QByteArray((const char*)s.toLocal8Bit(), s.length());
     915                    regValueBuff = QByteArray((const char*)s.toL(), s.length());
    900916                } );
    901917            } else {
     
    906922                        regValueBuff += QByteArray((const char*)s.utf16(), (s.length() + 1)*2);
    907923                    }, {
    908                         regValueBuff += QByteArray((const char*)s.toLocal8Bit(), s.length() + 1);
     924                        regValueBuff += QByteArray((const char*)s.toL(), s.length() + 1);
    909925                    } );
    910926                }
     
    926942        }
    927943
    928         case QVariant::ByteArray:
    929             // fallthrough intended
    930 
    931944        default: {
    932945            // If the string does not contain '\0', we can use REG_SZ, the native registry
     
    938951                    regValueBuff = QByteArray((const char*)s.utf16(), s.length()*2);
    939952                }, {
    940                     regValueBuff = QByteArray((const char*)s.toLocal8Bit(), s.length());
     953                    regValueBuff = QByteArray((const char*)s.toL(), s.length());
    941954                } );
    942955            } else {
     
    944957                    regValueBuff = QByteArray((const char*)s.utf16(), (s.length() + 1)*2);
    945958                }, {
    946                     regValueBuff = QByteArray((const char*)s.toLocal8Bit(), s.length() + 1);
     959                    regValueBuff = QByteArray((const char*)s.toL(), s.length() + 1);
    947960                } );
    948961            }
  • trunk/src/corelib/io/qsettings_win.cpp

    r2 r229  
    545545    }
    546546
     547
     548
     549
     550
     551
     552
     553
     554
    547555    switch (dataType) {
    548556        case REG_EXPAND_SZ:
     
    553561                    s = QString::fromUtf16(((const ushort*)data.constData()));
    554562                }, {
    555                     s = QString::fromLocal8Bit(data.constData());
     563                    s = QString::fromL(data.constData());
    556564                } );
    557565            }
     
    591599                    s = QString::fromUtf16((const ushort*)data.constData(), data.size()/2);
    592600                }, {
    593                     s = QString::fromLocal8Bit(data.constData(), data.size());
     601                    s = QString::fromL(data.constData(), data.size());
    594602                } );
    595603            }
     
    634642    if (deleteWriteHandleOnExit && writeHandle() != 0) {
    635643#if defined(Q_OS_WINCE)
    636         remove(regList.at(0).key()); 
     644        remove(regList.at(0).key());
    637645#else
    638646        DWORD res;
     
    744752    QByteArray regValueBuff;
    745753
     754
     755
     756
     757
     758
     759
     760
     761
    746762    // Determine the type
    747763    switch (value.type()) {
     
    765781                    regValueBuff = QByteArray((const char*)s.utf16(), s.length()*2);
    766782                }, {
    767                     regValueBuff = QByteArray((const char*)s.toLocal8Bit(), s.length());
     783                    regValueBuff = QByteArray((const char*)s.toL(), s.length());
    768784                } );
    769785            } else {
     
    774790                        regValueBuff += QByteArray((const char*)s.utf16(), (s.length() + 1)*2);
    775791                    }, {
    776                         regValueBuff += QByteArray((const char*)s.toLocal8Bit(), s.length() + 1);
     792                        regValueBuff += QByteArray((const char*)s.toL(), s.length() + 1);
    777793                    } );
    778794                }
     
    794810        }
    795811
    796         case QVariant::ByteArray:
    797             // On Win95/98/Me QString::toLocal8Bit() fails to handle chars > 0x7F. So we don't go through variantToString() at all.
    798             if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) {
    799                 QByteArray ba = value.toByteArray();
    800                 regValueBuff = "@ByteArray(";
    801                 regValueBuff += ba;
    802                 regValueBuff += ')';
    803                 if (ba.contains('\0')) {
    804                     type = REG_BINARY;
    805                 } else {
    806                     type = REG_SZ;
    807                     regValueBuff += '\0';
    808                 }
    809                    
    810                 break;
    811             }
    812             // fallthrough intended
    813 
    814812        default: {
    815813            // If the string does not contain '\0', we can use REG_SZ, the native registry
     
    821819                    regValueBuff = QByteArray((const char*)s.utf16(), s.length()*2);
    822820                }, {
    823                     regValueBuff = QByteArray((const char*)s.toLocal8Bit(), s.length());
     821                    regValueBuff = QByteArray((const char*)s.toL(), s.length());
    824822                } );
    825823            } else {
     
    827825                    regValueBuff = QByteArray((const char*)s.utf16(), (s.length() + 1)*2);
    828826                }, {
    829                     regValueBuff = QByteArray((const char*)s.toLocal8Bit(), s.length() + 1);
     827                    regValueBuff = QByteArray((const char*)s.toL(), s.length() + 1);
    830828                } );
    831829            }
Note: See TracChangeset for help on using the changeset viewer.