VirtualBox

Changeset 50793 in vbox


Ignore:
Timestamp:
Mar 14, 2014 9:13:23 PM (11 years ago)
Author:
vboxsync
Message:

iprt: Added RTSTR_VALIDATE_ENCODING_EXACT_LENGTH for RTStrValidateEncodingEx and RTUtf16ValidateEncodingEx.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/string.h

    r50792 r50793  
    677677 * VERR_BUFFER_OVERFLOW will be returned if the check fails. */
    678678#define RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED     RT_BIT_32(0)
     679/** Check that the string is exactly the given length.
     680 * If it terminates early, VERR_BUFFER_UNDERFLOW will be returned.  When used
     681 * together with RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED, the given length must
     682 * include the terminator or VERR_BUFFER_OVERFLOW will be returned. */
     683#define RTSTR_VALIDATE_ENCODING_EXACT_LENGTH        RT_BIT_32(1)
    679684/** @} */
    680685
     
    684689 * @returns iprt status code.
    685690 * @param   psz         The string.
    686  * @param   cch         The max string length. Use RTSTR_MAX to process the entire string.
     691 * @param   cch         The max string length (/ size).  Use RTSTR_MAX to
     692 *                      process the entire string.
    687693 * @param   fFlags      Combination of RTSTR_VALIDATE_ENCODING_XXX flags.
    688694 */
     
    33583364 * @returns iprt status code.
    33593365 * @param   pwsz        The string.
    3360  * @param   cch         The max string length. Use RTSTR_MAX to process the entire string.
     3366 * @param   cwc         The max string length (/ size) in UTF-16 units. Use
     3367 *                      RTSTR_MAX to process the entire string.
    33613368 * @param   fFlags      Combination of RTSTR_VALIDATE_ENCODING_XXX flags.
    33623369 */
  • trunk/src/VBox/Runtime/common/string/utf-16.cpp

    r50792 r50793  
    319319RTDECL(int) RTUtf16ValidateEncodingEx(PCRTUTF16 pwsz, size_t cwc, uint32_t fFlags)
    320320{
    321     AssertReturn(!(fFlags & ~(RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED)), VERR_INVALID_PARAMETER);
     321    AssertReturn(!(fFlags & ~(RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED | RTSTR_VALIDATE_ENCODING_EXACT_LENGTH)),
     322                 VERR_INVALID_PARAMETER);
    322323    AssertPtr(pwsz);
    323324
     
    330331    if (RT_SUCCESS(rc))
    331332    {
    332         if (    (fFlags & RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED)
    333             &&  cwcActual >= cwc)
     333        if (fFlags & RTSTR_VALIDATE_ENCODING_EXACT_LENGTH)
     334        {
     335            if (fFlags & RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED)
     336                cwcActual++;
     337            if (cwcActual == cwc)
     338                rc = VINF_SUCCESS;
     339            else if (cwcActual < cwc)
     340                rc = VERR_BUFFER_UNDERFLOW;
     341            else
     342                rc = VERR_BUFFER_OVERFLOW;
     343        }
     344        else if (    (fFlags & RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED)
     345                 &&  cwcActual >= cwc)
    334346            rc = VERR_BUFFER_OVERFLOW;
    335347    }
  • trunk/src/VBox/Runtime/common/string/utf-8.cpp

    r48935 r50793  
    301301RTDECL(int) RTStrValidateEncodingEx(const char *psz, size_t cch, uint32_t fFlags)
    302302{
    303     AssertReturn(!(fFlags & ~(RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED)), VERR_INVALID_PARAMETER);
     303    AssertReturn(!(fFlags & ~(RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED | RTSTR_VALIDATE_ENCODING_EXACT_LENGTH)),
     304                 VERR_INVALID_PARAMETER);
    304305    AssertPtr(psz);
    305306
     
    312313    if (RT_SUCCESS(rc))
    313314    {
    314         if (    (fFlags & RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED)
    315             &&  cchActual >= cch)
     315        if (fFlags & RTSTR_VALIDATE_ENCODING_EXACT_LENGTH)
     316        {
     317            if (fFlags & RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED)
     318                cchActual++;
     319            if (cchActual == cch)
     320                rc = VINF_SUCCESS;
     321            else if (cchActual < cch)
     322                rc = VERR_BUFFER_UNDERFLOW;
     323            else
     324                rc = VERR_BUFFER_OVERFLOW;
     325        }
     326        else if (    (fFlags & RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED)
     327                 &&  cchActual >= cch)
    316328            rc = VERR_BUFFER_OVERFLOW;
    317329    }
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