VirtualBox

Changeset 101344 in vbox for trunk/src/VBox/Main/xml


Ignore:
Timestamp:
Oct 4, 2023 7:35:14 PM (19 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
159345
Message:

Main/Settings.cpp: Fixed incorrect and inefficient (you don't use find) endsWith() emulation in MachineConfigFile::convertGuestOSTypeSuffix (regression from r159257). Use new RTCString::endsWith methods. Untested. bugref:10384

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/xml/Settings.cpp

    r101274 r101344  
    68266826}
    68276827
    6828 const struct {
     6828static struct
     6829{
    68296830    const char *pcszOld;
    68306831    const char *pcszNew;
    6831 } aConvertGuestOSTypesPre1_5[] =
     6832} const g_aConvertGuestOSTypesPre1_5[] =
    68326833{
    68336834    { "unknown", "Other" },
     
    68686869};
    68696870
     6871/* static */
    68706872void MachineConfigFile::convertGuestOSTypeFromPre1_5(Utf8Str &str)
    68716873{
    6872     for (size_t u = 0; u < RT_ELEMENTS(aConvertGuestOSTypesPre1_5); ++u)
    6873         if (str == aConvertGuestOSTypesPre1_5[u].pcszOld)
    6874         {
    6875             str = aConvertGuestOSTypesPre1_5[u].pcszNew;
     6874    for (size_t idx = 0; idx < RT_ELEMENTS(g_aConvertGuestOSTypesPre1_5); ++idx)
     6875        if (str == g_aConvertGuestOSTypesPre1_5[idx].pcszOld)
     6876        {
     6877            str = g_aConvertGuestOSTypesPre1_5[idx].pcszNew;
    68766878            break;
    68776879        }
     
    68816883 * Static function to convert a guest OS type ID suffix.
    68826884 *
    6883  * @returns \c true if suffix got converted, or \c false if not.
    68846885 * @param   strOsType               Guest OS type ID to convert.
    68856886 * @param   pszToReplace            Suffix to replace.
     
    68876888 */
    68886889/* static */
    6889 bool MachineConfigFile::convertGuestOSTypeSuffix(com::Utf8Str &strOsType, const char *pszToReplace, const char *pszReplacement)
    6890 {
    6891     AssertPtrReturn(pszToReplace, false);
    6892     AssertPtrReturn(pszReplacement, false);
    6893 
    6894     size_t const cchSuffix = strlen(pszToReplace);
    6895     size_t const idxSuffix = strOsType.find(pszToReplace);
    6896     if (idxSuffix == strOsType.length() - cchSuffix) /* Be extra cautious to only replace the real suffix. */
    6897     {
    6898         strOsType.replace(idxSuffix, cchSuffix, pszReplacement);
    6899         return true;
    6900     }
    6901     return false;
     6890void MachineConfigFile::convertGuestOSTypeSuffix(com::Utf8Str &strOsType, const char *pszToReplace, const char *pszReplacement)
     6891{
     6892    size_t const cchToReplace = strlen(pszToReplace);
     6893    if (strOsType.endsWith(pszToReplace, cchToReplace))
     6894        strOsType.replace(strOsType.length() - cchToReplace, cchToReplace, pszReplacement);
    69026895}
    69036896
     
    69136906 *          compatibility with older VBox versions.
    69146907 */
     6908/* static */
    69156909void MachineConfigFile::convertGuestOSTypeFromPre1_20(Utf8Str &str)
    69166910{
     
    69276921 *          know about the new suffix.
    69286922 */
     6923/* static */
    69296924void MachineConfigFile::convertGuestOSTypeToPre1_20(Utf8Str &str)
    69306925{
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette