Fix: tracer: utf16/32 gather types handling
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 15 May 2024 14:34:46 +0000 (10:34 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 15 May 2024 14:34:46 +0000 (10:34 -0400)
tracer_convert_string_to_utf8 should return the size of the input
(including null terminator) rather than the size of the utf8 output.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/tracer.c

index 1973c4cedeb39f0e669ed2a9de77af6c18c14e49..986f200e4e25bbf0b7c04e9f7da2c25ceccc663e 100644 (file)
@@ -69,7 +69,7 @@ void tracer_convert_string_to_utf8(const void *p, uint8_t unit_size, enum side_t
                size_t *strlen_with_null,
                char **output_str)
 {
-       size_t ret, inbytesleft = 0, outbytesleft, bufsize;
+       size_t ret, inbytesleft = 0, outbytesleft, bufsize, input_size;
        const char *str = p, *fromcode;
        char *inbuf = (char *) p, *outbuf, *buf;
        iconv_t cd;
@@ -101,6 +101,7 @@ void tracer_convert_string_to_utf8(const void *p, uint8_t unit_size, enum side_t
                }
                for (; *p16; p16++)
                        inbytesleft += 2;
+               input_size = inbytesleft + 2;
                /*
                 * Worse case is U+FFFF UTF-16 (2 bytes) converting to
                 * { ef, bf, bf } UTF-8 (3 bytes).
@@ -129,6 +130,7 @@ void tracer_convert_string_to_utf8(const void *p, uint8_t unit_size, enum side_t
                }
                for (; *p32; p32++)
                        inbytesleft += 4;
+               input_size = inbytesleft + 4;
                /*
                 * Each 4-byte UTF-32 character converts to at most a
                 * 4-byte UTF-8 character.
@@ -167,7 +169,7 @@ void tracer_convert_string_to_utf8(const void *p, uint8_t unit_size, enum side_t
                abort();
        }
        if (strlen_with_null)
-               *strlen_with_null = outbuf - buf;
+               *strlen_with_null = input_size;
        *output_str = buf;
 }
 
This page took 0.024881 seconds and 4 git commands to generate.