Skip to content

Commit 7ef252f

Browse files
authored
lstrdup used bad malloc
1 parent b2fa321 commit 7ef252f

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

nanolibc.h

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -603,23 +603,6 @@ static allnonnull const wchar_t *lstrstrW(const wchar_t *haystack, const wchar_t
603603
return NULL;
604604
}
605605

606-
607-
static char *lstrdupA(const char *s)
608-
{
609-
size_t olen_byte = (strlenL(s) + 1) * sizeof(char);
610-
char *dup = (char *)malloc(olen_byte);
611-
if(!dup) return NULL;
612-
return (char *)memmove(dup, s, olen_byte);
613-
}
614-
615-
static wchar_t *lstrdupW(const wchar_t *s)
616-
{
617-
size_t olen_byte = (wcslenL(s) + 1) * sizeof(wchar_t);
618-
wchar_t *dup = (wchar_t *)malloc(olen_byte);
619-
if(!dup) return NULL;
620-
return (wchar_t *)memmove(dup, s, olen_byte);
621-
}
622-
623606
#define itostrA itoaL
624607
#define itostrW itowL
625608
#define strtoiA atoiL
@@ -817,4 +800,23 @@ static void *db_realloc(void *x, size_t sz, const char *file, int ln)
817800

818801
#endif /* DEBUG_MALLOC */
819802

803+
804+
static char *lstrdupA(const char *s)
805+
{
806+
size_t olen_byte = (strlenL(s) + 1) * sizeof(char);
807+
char *dup = (char *)malloc(olen_byte);
808+
if(!dup) return NULL;
809+
memcpy(dup, s, olen_byte);
810+
return dup;
811+
}
812+
813+
static wchar_t *lstrdupW(const wchar_t *s)
814+
{
815+
size_t olen_byte = (wcslenL(s) + 1) * sizeof(wchar_t);
816+
wchar_t *dup = (wchar_t *)malloc(olen_byte);
817+
if(!dup) return NULL;
818+
memcpy(dup, s, olen_byte);
819+
return dup;
820+
}
821+
820822
#endif

0 commit comments

Comments
 (0)