Changeset 50793 in vbox
- Timestamp:
- Mar 14, 2014 9:13:23 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
include/iprt/string.h (modified) (3 diffs)
-
src/VBox/Runtime/common/string/utf-16.cpp (modified) (2 diffs)
-
src/VBox/Runtime/common/string/utf-8.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/string.h
r50792 r50793 677 677 * VERR_BUFFER_OVERFLOW will be returned if the check fails. */ 678 678 #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) 679 684 /** @} */ 680 685 … … 684 689 * @returns iprt status code. 685 690 * @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. 687 693 * @param fFlags Combination of RTSTR_VALIDATE_ENCODING_XXX flags. 688 694 */ … … 3358 3364 * @returns iprt status code. 3359 3365 * @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. 3361 3368 * @param fFlags Combination of RTSTR_VALIDATE_ENCODING_XXX flags. 3362 3369 */ -
trunk/src/VBox/Runtime/common/string/utf-16.cpp
r50792 r50793 319 319 RTDECL(int) RTUtf16ValidateEncodingEx(PCRTUTF16 pwsz, size_t cwc, uint32_t fFlags) 320 320 { 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); 322 323 AssertPtr(pwsz); 323 324 … … 330 331 if (RT_SUCCESS(rc)) 331 332 { 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) 334 346 rc = VERR_BUFFER_OVERFLOW; 335 347 } -
trunk/src/VBox/Runtime/common/string/utf-8.cpp
r48935 r50793 301 301 RTDECL(int) RTStrValidateEncodingEx(const char *psz, size_t cch, uint32_t fFlags) 302 302 { 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); 304 305 AssertPtr(psz); 305 306 … … 312 313 if (RT_SUCCESS(rc)) 313 314 { 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) 316 328 rc = VERR_BUFFER_OVERFLOW; 317 329 }
Note:
See TracChangeset
for help on using the changeset viewer.

