forked from osmocom/wireshark
wmem: Make wmem_strbuf_utf8_validate endpptr param optional
Often we don't care about the last valid character, just if the buffer is valid.
This commit is contained in:
parent
0928a25d1f
commit
f4965d5dec
|
@ -419,17 +419,27 @@ static bool
|
||||||
string_utf8_validate(const char *str, ssize_t max_len, const char **endpptr)
|
string_utf8_validate(const char *str, ssize_t max_len, const char **endpptr)
|
||||||
{
|
{
|
||||||
bool valid;
|
bool valid;
|
||||||
|
const char *endp;
|
||||||
|
|
||||||
if (max_len <= 0)
|
if (max_len <= 0) {
|
||||||
|
if (endpptr) {
|
||||||
|
*endpptr = str;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
valid = g_utf8_validate(str, max_len, endpptr);
|
valid = g_utf8_validate(str, max_len, &endp);
|
||||||
if (valid || **endpptr != '\0')
|
|
||||||
|
if (valid || *endp != '\0') {
|
||||||
|
if (endpptr) {
|
||||||
|
*endpptr = endp;
|
||||||
|
}
|
||||||
return valid;
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
/* Invalid because of a nul byte. Skip nuls and continue. */
|
/* Invalid because of a nul byte. Skip nuls and continue. */
|
||||||
max_len -= *endpptr - str;
|
max_len -= endp - str;
|
||||||
str = *endpptr;
|
str = endp;
|
||||||
while (max_len > 0 && *str == '\0') {
|
while (max_len > 0 && *str == '\0') {
|
||||||
str++;
|
str++;
|
||||||
max_len--;
|
max_len--;
|
||||||
|
|
|
@ -156,6 +156,11 @@ WS_DLL_PUBLIC
|
||||||
void
|
void
|
||||||
wmem_strbuf_destroy(wmem_strbuf_t *strbuf);
|
wmem_strbuf_destroy(wmem_strbuf_t *strbuf);
|
||||||
|
|
||||||
|
/* Validates the string buffer as UTF-8.
|
||||||
|
* Unlike g_utf8_validate(), accepts embedded NUL bytes as valid UTF-8.
|
||||||
|
* If endpptr is non-NULL, then the end of the valid range is stored there
|
||||||
|
* (i.e. the first invalid character, or the end of the buffer otherwise).
|
||||||
|
*/
|
||||||
WS_DLL_PUBLIC
|
WS_DLL_PUBLIC
|
||||||
bool
|
bool
|
||||||
wmem_strbuf_utf8_validate(wmem_strbuf_t *strbuf, const char **endptr);
|
wmem_strbuf_utf8_validate(wmem_strbuf_t *strbuf, const char **endptr);
|
||||||
|
|
Loading…
Reference in New Issue