fix an error in strdup clone
authorNiki <david.roulet@solidaris.be>
Mon, 24 Jun 2024 13:57:24 +0000 (15:57 +0200)
committerNiki <david.roulet@solidaris.be>
Mon, 24 Jun 2024 13:57:24 +0000 (15:57 +0200)
cstring.c
cutils.c

index 58481ecbdf4baafa69fe9d59762c1a8997b180ce..5a4d81ac2510c8dc6c4ec0d9a09d6aec8209c2d6 100644 (file)
--- 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) {
index 4547c4bd3a793859fca8f3b9c440754736fcee72..87ffa9e255b52904c33805e9e9904594f43288fb 100644 (file)
--- 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;
 }