hirc

IRC client
Log | Files | Refs

commit c0f783f27cd589499a4bf3489e93ee0ebb3ba2fd
parent 128ab339babedc0117741de08dc7663479577836
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 27 Mar 2022 16:45:15 +0100

Avoid segfault on wctos/stowc with NULL

Diffstat:
Msrc/mem.c | 4++++
Msrc/ui.c | 2+-
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/mem.c b/src/mem.c @@ -98,6 +98,8 @@ stowc(char *str) { wchar_t *ret; size_t len; + if (!str) return NULL; + len = mbstowcs(NULL, str, 0) + 1; ret = emalloc(len * sizeof(wchar_t)); mbstowcs(ret, str, len); @@ -109,6 +111,8 @@ wctos(wchar_t *str) { char *ret; size_t len; + if (!str) return NULL; + len = wcstombs(NULL, str, 0) + 1; ret = emalloc(len); wcstombs(ret, str, len); diff --git a/src/ui.c b/src/ui.c @@ -691,7 +691,7 @@ getcmd: type = 2; else if (wcscmp(cmd, L"format") == 0) type = 3; - if (type && ctok == 1) { + if (type && ctok == 1 && toks[1]) { wstem = toks[1]; p = wctos(wstem);