Date: Mon, 19 Aug 2013 12:08:30 GMT From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r256140 - soc2013/mattbw/backend/query Message-ID: <201308191208.r7JC8UtC084557@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308191208.r7JC8UtC084557>