PERFORCE change 130693 for review
Garrett Cooper
gcooper at FreeBSD.org
Wed Dec 12 03:44:15 PST 2007
http://perforce.freebsd.org/chv.cgi?CH=130693
Change 130693 by gcooper at shiina-ibook on 2007/12/12 11:44:00
-Finish off string checking @todo.
-Style
-Move common code to a goto / label instead of repeating it n times (to avoid errors).
Affected files ...
.. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_repo_ftp.c#3 edit
Differences ...
==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_repo_ftp.c#3 (text+ko) ====
@@ -244,7 +244,7 @@
//}
/* Get the extension */
- if (pkg_name_has_extension(pkg_name))
+ if (pkg_name_has_extension(pkg_name) < 0)
ext = "";
else
ext = ".tbz";
@@ -278,7 +278,6 @@
/**
* @brief Creates a ftp_repo object for repo->data
- * @todo Free the object at all failure points
* @return A ftp_repo object or NULL
*/
static struct ftp_repo *
@@ -288,7 +287,7 @@
f_repo = malloc(sizeof(struct ftp_repo));
if (f_repo == NULL)
- return NULL;
+ goto ftp_create_repo_fail;
/* Figure out the site */
if (site == NULL)
@@ -297,7 +296,7 @@
f_repo->site = strdup(site);
if (f_repo->site == NULL)
- return NULL;
+ goto ftp_create_repo_fail;
/* Figure out the path */
f_repo->path = NULL;
@@ -306,9 +305,10 @@
int i, reldate;
reldate = getosreldate();
- if(reldate > MAX_VERSION) { /* bogus osreldate?? */
- return NULL;
- }
+
+ /* bogus osreldate?? */
+ if (reldate > MAX_VERSION)
+ goto ftp_create_repo_fail;
uname(&u);
@@ -335,7 +335,7 @@
}
if (f_repo->path == NULL)
- return NULL;
+ goto ftp_create_repo_fail;
f_repo->cache = 0;
if (cache_dir != NULL) {
@@ -344,12 +344,17 @@
}
return f_repo;
+
+ftp_create_repo_fail:
+ ftp_free(f_repo);
+ return NULL;
+
}
/**
* @brief Find if a name has a known extension
- * @todo Return 0 and -1 like other functions
- * @return 1 if name ends with ".t[bg]z", otherwise 0
+ * @return -1 on the extension not being found; 0 if
+ * name ends with ".t[bg]z".
*/
static int
pkg_name_has_extension(const char *name)
@@ -358,12 +363,12 @@
p = strrchr(name, '.');
if (p == NULL)
- return (0);
- if (strcmp(p, ".tbz")==0)
- return (1);
- if (strcmp(p, ".tgz")==0)
- return (1);
- return (0);
+ return -1;
+ if (strcmp(p, ".tbz") == 0)
+ return -1;
+ if (strcmp(p, ".tgz") == 0)
+ return -1;
+ return 0;
}
/**
More information about the p4-projects
mailing list