Skip to content

Commit 5e8b27a

Browse files
committed
Use strdup instead of malloc and strcpy
1 parent 04439c6 commit 5e8b27a

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

ext/socket/getaddrinfo.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ static const char *const ai_errlist[] = {
171171

172172
#define GET_CANONNAME(ai, str) \
173173
if (pai->ai_flags & AI_CANONNAME) {\
174-
if (((ai)->ai_canonname = (char *)malloc(strlen(str) + 1)) != NULL) {\
175-
strcpy((ai)->ai_canonname, (str));\
176-
} else {\
174+
if (((ai)->ai_canonname = strdup(str)) == NULL) {\
177175
error = EAI_MEMORY;\
178176
goto free;\
179177
}\

0 commit comments

Comments
 (0)