Skip to content

Commit

Permalink
utf8: fixed bug in u8_strlen
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy-Yakovenko committed Jun 21, 2017
1 parent b9e26c3 commit 0955071
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tf.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,9 +867,10 @@ tf_func_pad_impl (ddb_tf_context_t *ctx, int argc, const uint16_t *arglens, cons
// only accept first character
nb_pad_char = u8_offset(pad_char_str, 1);
pad_char_str[nb_pad_char] = 0;

}

int str_chars = u8_strlen(str);

if (str_chars >= padlen_chars) {
u8_strnbcpy(out, str, min (str_len, outlen));
return str_len;
Expand Down
3 changes: 2 additions & 1 deletion utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,14 @@ int u8_strlen(char *s)
int32_t count = 0;
int32_t i = 0;

while (u8_nextchar(s, &i) != 0)
while (s[i] && u8_nextchar(s, &i) != 0)
count++;

return count;
}

/* reads the next utf-8 sequence out of a string, updating an index */
// NOTE: a valid UTF8 sequence is expected, no validity or 0 checks are performed.
uint32_t u8_nextchar(const char *s, int32_t *i)
{
uint32_t ch = 0;
Expand Down

0 comments on commit 0955071

Please sign in to comment.