Project

General

Profile

Feature #28 ยป 0017-fc_utf8.c-Drop-asserts-of-parameters-with-nonnull-at.patch

Marko Lindqvist, 12/05/2023 07:39 AM

View differences:

utility/fc_utf8.c
****************************************************************************/
bool fc_utf8_char_validate(const char *utf8_char)
{
fc_assert_ret_val(NULL != utf8_char, FALSE);
return base_fc_utf8_char_validate(utf8_char, FC_UTF8_CHAR_SIZE(utf8_char));
}
......
****************************************************************************/
const char *fc_utf8_find_next_char(const char *utf8_char)
{
fc_assert_ret_val(NULL != utf8_char, NULL);
do {
utf8_char++;
} while (0 == FC_UTF8_CHAR_SIZE(utf8_char));
......
const char *fc_utf8_find_prev_char(const char *utf8_char,
const char *utf8_string)
{
fc_assert_ret_val(NULL != utf8_char, NULL);
for (utf8_char--; utf8_char > utf8_string; utf8_char--) {
if (0 != FC_UTF8_CHAR_SIZE(utf8_char)) {
return utf8_char;
......
{
char size;
fc_assert_ret_val(NULL != utf8_string, FALSE);
while ('\0' != *utf8_string) {
size = FC_UTF8_CHAR_SIZE(utf8_string);
if (!base_fc_utf8_char_validate(utf8_string, size)) {
......
if (NULL != end) {
*end = utf8_string;
}
return TRUE;
}
......
{
unsigned char size;
fc_assert_ret_val(NULL != utf8_string, FALSE);
while ('\0' != *utf8_string) {
size = FC_UTF8_CHAR_SIZE(utf8_string);
if (!base_fc_utf8_char_validate(utf8_string, size)) {
if (NULL != end) {
if (end != NULL) {
*end = utf8_string;
}
return FALSE;
}
if (size > byte_len) {
if (NULL != end) {
if (end != NULL) {
*end = utf8_string;
}
return FALSE;
......
utf8_string += size;
}
if (NULL != end) {
if (end != NULL) {
*end = utf8_string;
}
......
{
char *end;
fc_assert_ret_val(NULL != utf8_string, NULL);
if (!fc_utf8_validate(utf8_string, (const char **) &end)) {
*end = '\0';
}
......
{
char *end;
fc_assert_ret_val(NULL != utf8_string, NULL);
if (!fc_utf8_validate_len(utf8_string, byte_len, (const char **) &end)) {
*end = '\0';
}
return utf8_string;
}
......
size_t size;
char *ret;
fc_assert_ret_val(NULL != utf8_string, NULL);
(void) fc_utf8_validate(utf8_string, &end);
size = end - utf8_string;
ret = fc_malloc(size + 1); /* Keep a spot for '\0'. */
......
****************************************************************************/
char *fc_utf8_validate_rep_len(char *utf8_string, size_t byte_len)
{
fc_assert_ret_val(NULL != utf8_string, NULL);
if (0 < byte_len) {
char copy[byte_len];
fc_strlcpy(copy, utf8_string, byte_len);
base_fc_utf8_strlcpy_rep(utf8_string, copy, byte_len);
}
return utf8_string;
}
......
size_t size = 1; /* '\0'. */
char char_size;
fc_assert_ret_val(NULL != utf8_string, NULL);
/* Check needed size. */
utf8_char = utf8_string;
while ('\0' != *utf8_char) {
......
{
size_t len;
fc_assert_ret_val(NULL != utf8_string, 0);
for (len = 0; '\0' != *utf8_string; len++) {
utf8_string = fc_ut8_next_char(utf8_string);
}
return len;
}
/************************************************************************//**
This is a variant of fc_strlcpy() to ensure the result will be a valid
UTF-8 string. It truncates the string at the first UTF-8 invalid
......
****************************************************************************/
size_t fc_utf8_strlcpy_trunc(char *dest, const char *src, size_t n)
{
fc_assert_ret_val(NULL != dest, -1);
fc_assert_ret_val(NULL != src, -1);
fc_assert_ret_val(0 < n, -1);
return base_fc_utf8_strlcpy_trunc(dest, src, n);
......
****************************************************************************/
size_t fc_utf8_strlcpy_rep(char *dest, const char *src, size_t n)
{
fc_assert_ret_val(NULL != dest, -1);
fc_assert_ret_val(NULL != src, -1);
fc_assert_ret_val(0 < n, -1);
return base_fc_utf8_strlcpy_rep(dest, src, n);
......
{
size_t len;
fc_assert_ret_val(NULL != dest, -1);
fc_assert_ret_val(NULL != src, -1);
fc_assert_ret_val(0 < n, -1);
len = strlen(dest);
fc_assert_ret_val(len < n, -1);
return len + base_fc_utf8_strlcpy_trunc(dest + len, src, n - len);
}
......
{
size_t len;
fc_assert_ret_val(NULL != dest, -1);
fc_assert_ret_val(NULL != src, -1);
fc_assert_ret_val(0 < n, -1);
len = strlen(dest);
fc_assert_ret_val(len < n, -1);
return len + base_fc_utf8_strlcpy_rep(dest + len, src, n - len);
}
......
va_start(args, format);
ret = fc_utf8_vsnprintf_trunc(str, n, format, args);
va_end(args);
return ret;
}
......
char *end;
int ret;
fc_assert_ret_val(NULL != str, -1);
fc_assert_ret_val(0 < n, -1);
fc_assert_ret_val(NULL != format, -1);
ret = fc_vsnprintf(str, n, format, args);
if (fc_utf8_validate(str, (const char **) &end)) {
......
char *end;
int ret;
fc_assert_ret_val(NULL != str, -1);
fc_assert_ret_val(0 < n, -1);
fc_assert_ret_val(NULL != format, -1);
ret = fc_vsnprintf(str, n, format, args);
if (fc_utf8_validate(str, (const char **) &end)) {
......
int ret;
va_list args;
fc_assert_ret_val(NULL != format, -1);
fc_assert_ret_val(NULL != str, -1);
fc_assert_ret_val(0 < n, -1);
len = strlen(str);
......
int ret;
va_list args;
fc_assert_ret_val(NULL != format, -1);
fc_assert_ret_val(NULL != str, -1);
fc_assert_ret_val(0 < n, -1);
len = strlen(str);
    (1-1/1)