From owner-p4-projects@FreeBSD.ORG Wed Dec 12 11:44:15 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1B83A16A418; Wed, 12 Dec 2007 11:44:15 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D59E116A421 for ; Wed, 12 Dec 2007 11:44:14 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id B5BE713C458 for ; Wed, 12 Dec 2007 11:44:14 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id lBCBiER5006143 for ; Wed, 12 Dec 2007 11:44:14 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id lBCBiEdO006140 for perforce@freebsd.org; Wed, 12 Dec 2007 11:44:14 GMT (envelope-from gcooper@FreeBSD.org) Date: Wed, 12 Dec 2007 11:44:14 GMT Message-Id: <200712121144.lBCBiEdO006140@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gcooper@FreeBSD.org using -f From: Garrett Cooper To: Perforce Change Reviews Cc: Subject: PERFORCE change 130693 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Dec 2007 11:44:15 -0000 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; } /**