From owner-svn-soc-all@FreeBSD.ORG Mon Aug 19 12:08:30 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 6DA5ED96 for ; Mon, 19 Aug 2013 12:08:30 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 406002A16 for ; Mon, 19 Aug 2013 12:08:30 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7JC8UAD084572 for ; Mon, 19 Aug 2013 12:08:30 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7JC8UtC084557 for svn-soc-all@FreeBSD.org; Mon, 19 Aug 2013 12:08:30 GMT (envelope-from mattbw@FreeBSD.org) Date: Mon, 19 Aug 2013 12:08:30 GMT Message-Id: <201308191208.r7JC8UtC084557@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r256140 - soc2013/mattbw/backend/query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Aug 2013 12:08:30 -0000 Author: mattbw Date: Mon Aug 19 12:08:29 2013 New Revision: 256140 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256140 Log: Fixed test failure. The code for checking whether or not there is a valid name was incorrectly inverted, so the valid IDs were being rejected, the query ID was full of nulls, and the test code then tried to strcmp them. Also strdup the arch and repo, as we free the split package ID later. Modified: soc2013/mattbw/backend/query/id.c Modified: soc2013/mattbw/backend/query/id.c ============================================================================== --- soc2013/mattbw/backend/query/id.c Mon Aug 19 12:00:15 2013 (r256139) +++ soc2013/mattbw/backend/query/id.c Mon Aug 19 12:08:29 2013 (r256140) @@ -29,7 +29,7 @@ typedef bool (*id_from_string_ptr) (const char *, struct query_id *); static char *join_namever(const char *name, const char *version); -static char *null_if_empty(char *in); +static char *strdup_null_if_empty(char *in); static struct query_id *query_id_array_alloc(unsigned int count); static struct query_id *query_id_array_from_strings(char **strings, unsigned int package_count, id_from_string_ptr id_from_string); static void query_id_array_free(struct query_id **query_ids_p, unsigned int count); @@ -134,7 +134,7 @@ /* We're not allowed to have an empty name or version. */ name = split_package_id[PK_PACKAGE_ID_NAME]; - have_name = !(name != NULL && name[0] != '\0'); + have_name = (name != NULL && name[0] != '\0'); version = split_package_id[PK_PACKAGE_ID_VERSION]; have_version = (version != NULL && version[0] != '\0'); @@ -147,10 +147,10 @@ query_id->namever = join_namever(name, version); arch = split_package_id[PK_PACKAGE_ID_ARCH]; - query_id->arch = null_if_empty(arch); + query_id->arch = strdup_null_if_empty(arch); repo = split_package_id[PK_PACKAGE_ID_DATA]; - query_id->repo = null_if_empty(repo); + query_id->repo = strdup_null_if_empty(repo); success = true; } @@ -191,13 +191,14 @@ } /* - * Returns NULL if the given string is NULL or empty, and the string otherwise. + * Returns NULL if the given string is NULL or empty, and a duplicate of the + * string otherwise. */ static char * -null_if_empty(char *in) +strdup_null_if_empty(char *in) { - return (in == NULL || in[0] == '\0' ? NULL : in); + return (in == NULL || in[0] == '\0') ? NULL : strdup(in); } static void