diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-07-23-19-13-03.bpo-41340.en20DT.rst b/Misc/NEWS.d/next/Core and Builtins/2020-07-23-19-13-03.bpo-41340.en20DT.rst new file mode 100644 index 00000000000000..dbc3d3400b9b0d --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-07-23-19-13-03.bpo-41340.en20DT.rst @@ -0,0 +1 @@ +Optimized strdup \ No newline at end of file diff --git a/Python/strdup.c b/Python/strdup.c index 6ce171b21fe6c4..c39c9ea1a15dce 100644 --- a/Python/strdup.c +++ b/Python/strdup.c @@ -4,9 +4,10 @@ char * strdup(const char *str) { if (str != NULL) { - char *copy = malloc(strlen(str) + 1); + size_t len = strlen(str) + 1; + char *copy = malloc(len); if (copy != NULL) - return strcpy(copy, str); + return memcpy(copy, str, len); } return NULL; }