From: Niki Date: Mon, 24 Jun 2024 13:57:24 +0000 (+0200) Subject: fix an error in strdup clone X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=6e1a12739841bc4f7d4e5a2fc8b36d72fc0e8cb2;p=cutils.git fix an error in strdup clone --- diff --git a/cstring.c b/cstring.c index 58481ec..5a4d81a 100644 --- a/cstring.c +++ b/cstring.c @@ -590,7 +590,9 @@ void cstring_change_case(cstring_t *self, int up) { size_t i = 0; while (i < self->length) { - count = mbrtowc(&wide, self->string + i, self->length - i, &state_from); + count = mbrtowc(&wide, + self->string + i, self->length - i, + &state_from); //incomplete (should not happen) if (count == (size_t) -2) { diff --git a/cutils.c b/cutils.c index 4547c4b..87ffa9e 100644 --- a/cutils.c +++ b/cutils.c @@ -38,6 +38,8 @@ size_t strnlen(const char *s, size_t maxlen) { char *strdup(const char *source) { size_t sz = strlen(source); char *new = malloc((sz + 1) * sizeof(char)); + if (!new) + return NULL; strcpy(new, source); return new; }