Skip to content

Commit 6ea6d91

Browse files
authored
fix: memory out of bounds
1 parent c217902 commit 6ea6d91

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/out_json.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,16 @@ static char *_path_field (const char *path);
281281

282282
// Converts to UTF-8
283283
#ifdef HAVE_NATIVE_WCHAR2
284-
# define VALUE_TEXT_TU(wstr) \
285-
if (wstr) \
286-
{ \
287-
wchar_t *_buf = malloc (6 * wcslen ((wchar_t *)wstr) + 2); \
288-
fprintf (dat->fh, "\"%ls\"", wcquote (_buf, (wchar_t *)wstr)); \
289-
free (_buf); \
290-
} \
291-
else \
292-
{ \
293-
fprintf (dat->fh, "\"%ls\"", wstr ? (wchar_t *)wstr : L""); \
284+
# define VALUE_TEXT_TU(wstr) \
285+
if (wstr) \
286+
{ \
287+
wchar_t *_buf = malloc ((6 * wcslen ((wchar_t *)wstr) + 1) * sizeof(wchar_t)); \
288+
fprintf (dat->fh, "\"%ls\"", wcquote (_buf, (wchar_t *)wstr)); \
289+
free (_buf); \
290+
} \
291+
else \
292+
{ \
293+
fprintf (dat->fh, "\"%ls\"", wstr ? (wchar_t *)wstr : L""); \
294294
}
295295
#else
296296
# define VALUE_TEXT_TU(wstr) print_wcquote (dat, (BITCODE_TU)wstr)

0 commit comments

Comments
 (0)