[Midnightbsd-cvs] src [12055] trunk/lib/libmport: handle nulls in fields better
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Tue Sep 18 18:50:40 EDT 2018
Revision: 12055
http://svnweb.midnightbsd.org/src/?rev=12055
Author: laffer1
Date: 2018-09-18 18:50:35 -0400 (Tue, 18 Sep 2018)
Log Message:
-----------
handle nulls in fields better
Modified Paths:
--------------
trunk/lib/libmport/db.c
trunk/lib/libmport/pkgmeta.c
Modified: trunk/lib/libmport/db.c
===================================================================
--- trunk/lib/libmport/db.c 2018-09-18 17:34:28 UTC (rev 12054)
+++ trunk/lib/libmport/db.c 2018-09-18 22:50:35 UTC (rev 12055)
@@ -347,7 +347,7 @@
mport_generate_master_schema(sqlite3 *db)
{
- RUN_SQL(db, "CREATE TABLE IF NOT EXISTS packages (pkg text NOT NULL, version text NOT NULL, origin text NOT NULL, prefix text NOT NULL, lang text, options text, status text default 'dirty', comment text, os_release text, cpe text, locked int NOT NULL, deprecated text, expiration_date int64, no_provide_shlib int, flavor text)");
+ RUN_SQL(db, "CREATE TABLE IF NOT EXISTS packages (pkg text NOT NULL, version text NOT NULL, origin text NOT NULL, prefix text NOT NULL, lang text, options text, status text default 'dirty', comment text, os_release text NOT NULL default '1.0', cpe text, locked int NOT NULL default '0', deprecated text default '', expiration_date int64 NOT NULL default '0', no_provide_shlib int NOT NULL default '0', flavor text default '')");
RUN_SQL(db, "CREATE UNIQUE INDEX IF NOT EXISTS packages_pkg ON packages (pkg)");
RUN_SQL(db, "CREATE INDEX IF NOT EXISTS packages_origin ON packages (origin)");
Modified: trunk/lib/libmport/pkgmeta.c
===================================================================
--- trunk/lib/libmport/pkgmeta.c 2018-09-18 17:34:28 UTC (rev 12054)
+++ trunk/lib/libmport/pkgmeta.c 2018-09-18 22:50:35 UTC (rev 12055)
@@ -464,27 +464,33 @@
}
/* os_release */
- if ((tmp = sqlite3_column_text(stmt, 6)) == NULL)
- return MPORT_OK;
+ if ((tmp = sqlite3_column_text(stmt, 6)) == NULL) {
+ if ((pack->os_release = strdup(MPORT_OSVERSION)) == NULL)
+ RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
+ } else {
+ if ((pack->os_release = strdup(tmp)) == NULL)
+ RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
+ }
- if ((pack->os_release = strdup(tmp)) == NULL)
- RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
-
pack->locked = sqlite3_column_int(stmt, 8);
/* CPE */
if ((tmp = sqlite3_column_text(stmt, 7)) == NULL) {
- return MPORT_OK;
+ if ((pack->cpe = strdup("")) == NULL)
+ RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
+ } else {
+ if ((pack->cpe = strdup(tmp)) == NULL)
+ RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
}
- if ((pack->cpe = strdup(tmp)) == NULL)
- RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
/* deprecated */
if ((tmp = sqlite3_column_text(stmt, 9)) == NULL) {
- return MPORT_OK;
+ if ((pack->deprecated = strdup("")) == NULL)
+ RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
+ } else {
+ if ((pack->deprecated = strdup(tmp)) == NULL)
+ RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
}
- if ((pack->deprecated = strdup(tmp)) == NULL)
- RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
pack->expiration_date = sqlite3_column_int64(stmt, 10);
@@ -492,7 +498,7 @@
/* flavor */
if ((tmp = sqlite3_column_text(stmt, 12)) == NULL) {
- return MPORT_OK;
+ return MPORT_OK; /* last field so we can exit here */
}
if ((pack->flavor = strdup(tmp)) == NULL)
RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
More information about the Midnightbsd-cvs
mailing list