Skip to content

Commit

Permalink
sds: use new utf8 decoder for sds_cat_utf8
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Dec 5, 2024
1 parent cbd1a28 commit 4b64b3b
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/flb_sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <fluent-bit/flb_log.h>
#include <fluent-bit/flb_sds.h>
#include <fluent-bit/flb_utf8.h>
#include <fluent-bit/flb_utils.h>

#include <stdarg.h>
#include <ctype.h>
Expand Down Expand Up @@ -279,13 +280,15 @@ flb_sds_t flb_sds_copy(flb_sds_t s, const char *str, int len)
return s;
}

flb_sds_t flb_sds_cat_utf8 (flb_sds_t *sds, const char *str, int str_len)
flb_sds_t flb_sds_cat_utf8(flb_sds_t *sds, const char *str, int str_len)
{
static const char int2hex[] = "0123456789abcdef";
int i;
int b;
int ret;
int hex_bytes;
int offset;
size_t size;
uint32_t cp;
uint32_t state = 0;
unsigned char c;
Expand All @@ -297,6 +300,7 @@ flb_sds_t flb_sds_cat_utf8 (flb_sds_t *sds, const char *str, int str_len)
s = *sds;
head = FLB_SDS_HEADER(s);

/* make sure we have at least str_len extra bytes available */
if (flb_sds_avail(s) <= str_len) {
tmp = flb_sds_increase(s, str_len);
if (tmp == NULL) {
Expand All @@ -306,6 +310,30 @@ flb_sds_t flb_sds_cat_utf8 (flb_sds_t *sds, const char *str, int str_len)
head = FLB_SDS_HEADER(s);
}

while (1) {
offset = head->len;
ret = flb_utils_write_str(s, &offset, flb_sds_alloc(s), str, str_len);
if (ret == FLB_FALSE) {
/* realloc */
size = flb_sds_alloc(s) * 2;
tmp = flb_sds_increase(s, size);
if (tmp == NULL) {
return NULL;
}
*sds = s = tmp;
head = FLB_SDS_HEADER(s);
}
else {
break;
}
}

flb_sds_len_set(s, offset);
s[head->len] = '\0';
return s;



for (i = 0; i < str_len; i++) {
if (flb_sds_avail(s) < 8) {
tmp = flb_sds_increase(s, 8);
Expand Down

0 comments on commit 4b64b3b

Please sign in to comment.