Date: Wed, 12 Dec 2007 11:44:14 GMT From: Garrett Cooper <gcooper@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 130693 for review Message-ID: <200712121144.lBCBiEdO006140@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=130693 Change 130693 by gcooper@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; } /**
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200712121144.lBCBiEdO006140>