VirtualBox

Ignore:
Timestamp:
Jan 14, 2011 2:16:45 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
69451
Message:

IPRT: fix rare crash in MiniString::substr(); rename substr() to substrCP() and add a substr that operates on bytes, not codepoints; more to come

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/string/ministring.cpp

    r35128 r35567  
    224224}
    225225
    226 MiniString MiniString::substr(size_t pos /*= 0*/, size_t n /*= npos*/)
     226MiniString MiniString::substrCP(size_t pos /*= 0*/, size_t n /*= npos*/)
    227227    const
    228228{
     
    256256
    257257                size_t cbCopy = psz - pFirst;
    258                 ret.reserve(cbCopy + 1); // may throw bad_alloc
    259 #ifndef RT_EXCEPTIONS_ENABLED
    260                 AssertRelease(capacity() >= cbCopy + 1);
    261 #endif
    262                 memcpy(ret.m_psz, pFirst, cbCopy);
    263                 ret.m_cch = cbCopy;
    264                 ret.m_psz[cbCopy] = '\0';
     258                if (cbCopy)
     259                {
     260                    ret.reserve(cbCopy + 1); // may throw bad_alloc
     261#ifndef RT_EXCEPTIONS_ENABLED
     262                    AssertRelease(capacity() >= cbCopy + 1);
     263#endif
     264                    memcpy(ret.m_psz, pFirst, cbCopy);
     265                    ret.m_cch = cbCopy;
     266                    ret.m_psz[cbCopy] = '\0';
     267                }
    265268            }
    266269        }
Note: See TracChangeset for help on using the changeset viewer.

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