From 4643eeef6761fdb9afc367521ad0f044c82d2255 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Thu, 6 Oct 2011 10:40:14 -0400 Subject: [PATCH] don't set variable we don't use don't check for NULL before XFREE strdup -> xstrdup --- amd/sun_map.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/amd/sun_map.c b/amd/sun_map.c index 0d1181f4..68096364 100644 --- a/amd/sun_map.c +++ b/amd/sun_map.c @@ -167,7 +167,7 @@ sun_strsub(const char *src, const char *str, const char *sub) (void)strncat(retval, sub, sub_size); (void)strncat(retval, str_end + 1, second_half); - if ((str_start = strstr(retval, str)) != NULL) { + if (strstr(retval, str) != NULL) { /* * If there is another occurrences of str call this function * recursively. @@ -206,7 +206,7 @@ sun_expand2amd(const char *str) * each of the replace attempt will fail and we'll move on to the * next char. */ - tmp = strdup(str); + tmp = xstrdup(str); for (pos = str; *pos != '\0'; pos++) { if (*pos != '$') { continue; @@ -258,9 +258,7 @@ sun_expand2amd(const char *str) } else { retval = tmp2; - if (tmp != NULL) { - XFREE(tmp); - } + XFREE(tmp); } return retval; @@ -311,19 +309,15 @@ sun_append_str(char *dest, * Try to convert any variable substitutions. If this function * returns a new string one or more var subs where expanded. */ - else if ((sub = sun_expand2amd(out)) != NULL) { + else if (out != NULL && (sub = sun_expand2amd(out)) != NULL) { out = sub; } if (out != NULL) { xstrlcat(dest, out, destlen); } - if (sub != NULL) { - XFREE(sub); - } - if (sub2 != NULL) { - XFREE(sub2); - } + XFREE(sub); + XFREE(sub2); } @@ -555,7 +549,7 @@ sun_entry2amd(const char *key, const char *s_entry_str) if (s_entry->mountpt_list != NULL) { /* multi-mount point */ sun_multi2amd(line_buff, sizeof(line_buff), key, s_entry); - retval = strdup(line_buff); + retval = xstrdup(line_buff); } else { /* single mount point */ @@ -563,12 +557,12 @@ sun_entry2amd(const char *key, const char *s_entry_str) if (NSTREQ(s_entry->fstype, SUN_NFS_TYPE, strlen(SUN_NFS_TYPE))) { /* NFS Type */ sun_nfs2amd(line_buff, sizeof(line_buff), key, s_entry); - retval = strdup(line_buff); + retval = xstrdup(line_buff); } else if (NSTREQ(s_entry->fstype, SUN_HSFS_TYPE, strlen(SUN_HSFS_TYPE))) { /* HSFS Type (CD fs) */ sun_hsfs2amd(line_buff, sizeof(line_buff), key, s_entry); - retval = strdup(line_buff); + retval = xstrdup(line_buff); } /* * XXX: The following fstypes are not yet supported. @@ -595,13 +589,11 @@ sun_entry2amd(const char *key, const char *s_entry_str) else { plog(XLOG_INFO, "No SUN fstype specified defaulting to NFS."); sun_nfs2amd(line_buff, sizeof(line_buff), key, s_entry); - retval = strdup(line_buff); + retval = xstrdup(line_buff); } } err: - if (s_entry != NULL) { - XFREE(s_entry); - } + XFREE(s_entry); return retval; } -- 2.43.0