From 9a324f14e7c98a302d7276d7c151ccef9242c9f9 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Fri, 30 Mar 2012 19:18:47 +0100 Subject: [PATCH] libafscp: Use strdup, rather than rolling our own A = malloc(strlen(B)+ 1); memset(A, 0, strlen(B) + 1); strlcpy(A, B, strlen(B) + 1); can be more simply written as A = strdup(B); Doing so also avoids a warning from clang that strlcpy isn't checking for A overflowing. Reviewed-on: http://gerrit.openafs.org/7077 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear (cherry picked from commit 1e30c00e7d9b45d65e819d39414939f2d5f7631b) Change-Id: I886bef77fdedb63d1c83e657c25d112e0a635db2 Reviewed-on: http://gerrit.openafs.org/11844 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk Reviewed-by: Stephan Wiesand --- src/libafscp/afscp_server.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libafscp/afscp_server.c b/src/libafscp/afscp_server.c index a5fb47d004..e67ee48a9d 100644 --- a/src/libafscp/afscp_server.c +++ b/src/libafscp/afscp_server.c @@ -121,9 +121,7 @@ afscp_CellByName(const char *cellname, const char *realmname) memset(thecell, 0, sizeof(struct afscp_cell)); strlcpy(thecell->name, cellname, sizeof(thecell->name)); if (realmname != NULL) { - thecell->realm = malloc(strlen(realmname) + 1); - memset(thecell->realm, 0, strlen(realmname) + 1); - strlcpy(thecell->realm, realmname, strlen(realmname) + 1); + thecell->realm = strdup(realmname); } else { thecell->realm = NULL; }