чување 70bd2d786f3c7cd50e191ef0c6d9ba04c9f1d551
родитељ 0fe7579ad5b53cb459aaf3156d10bf80ed7a6d49
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Fri, 13 Aug 2021 15:38:04 +0200
Fix: allocate additional byte for NUL
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 1, додавања: 3(+), брисања: 3(-)
diff --git a/util.c b/util.c
@@ -57,7 +57,7 @@ unicode_string_to_u8(char* s, const uint32_t* us, const size_t max)
size_t
u32_encode_tabs(uint32_t* s, size_t max)
{
- uint32_t* buf = calloc(max, sizeof(uint32_t));
+ uint32_t* buf = calloc(max+1, sizeof(uint32_t));
if (!buf)
return 0;
uint32_t* pbuf = buf;
@@ -88,7 +88,7 @@ u32_encode_tabs(uint32_t* s, size_t max)
size_t
u32_decode_tabs(uint32_t* s, size_t max)
{
- uint32_t* buf = calloc(max, sizeof(uint32_t));
+ uint32_t* buf = calloc(max+1, sizeof(uint32_t));
if (!buf)
return 0;
uint32_t* pbuf = buf;
@@ -192,7 +192,7 @@ u32_u8_strncpy(uint32_t* to, const char* from, size_t max)
size_t
u8_u32_strncpy(char* to, const uint32_t* from, size_t max)
{
- char* cfrom = calloc(u32_strlen(from)*6, 1);
+ char* cfrom = calloc(u32_strlen(from)*6+1, 1);
if (!cfrom)
return 0;
unicode_string_to_u8(cfrom, from, max);