From 5b48ff17484c198d3d6bac9de7618bbf56290dc0 Mon Sep 17 00:00:00 2001 From: Philip Guenther Date: Sun, 20 Apr 2014 22:31:56 +0000 Subject: Eliminate duplicated logic by switching from malloc+snprintf to asprintf ok beck@ --- lib/libcrypto/dso/dso_dlfcn.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/libcrypto/dso/dso_dlfcn.c b/lib/libcrypto/dso/dso_dlfcn.c index 245b9b14789..62b826ea430 100644 --- a/lib/libcrypto/dso/dso_dlfcn.c +++ b/lib/libcrypto/dso/dso_dlfcn.c @@ -307,30 +307,24 @@ static char * dlfcn_name_converter(DSO *dso, const char *filename) { char *translated; - int len, rsize, transform; - - len = strlen(filename); - rsize = len + 1; - transform = (strstr(filename, "/") == NULL); - if (transform) { - /* We will convert this to "%s.so" or "lib%s.so" etc */ - rsize += DSO_extlen; /* The length of ".so" */ + int ret; + + if (strchr(filename, '/') == NULL) { + /* Bare name, so convert to "%s.so" or "lib%s.so" */ if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) - rsize += 3; /* The length of "lib" */ + ret = asprintf(&translated, "lib%s" DSO_ext, filename); + else + ret = asprintf(&translated, "%s" DSO_ext, filename); + if (ret == -1) + translated = NULL; + } else { + /* Full path, so just duplicate it */ + translated = strdup(filename); } - translated = malloc(rsize); - if (translated == NULL) { + + if (translated == NULL) DSOerr(DSO_F_DLFCN_NAME_CONVERTER, DSO_R_NAME_TRANSLATION_FAILED); - return (NULL); - } - if (transform) { - if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) - snprintf(translated, rsize, "lib%s" DSO_ext, filename); - else - snprintf(translated, rsize, "%s" DSO_ext, filename); - } else - snprintf(translated, rsize, "%s", filename); return (translated); } -- cgit v1.2.3