From: Panu Matilainen Date: Wed, 20 Apr 2011 12:41:53 +0000 (+0300) Subject: Eliminate last three assert()'s from the backend X-Git-Tag: tznext/4.11.0.1.tizen20130304~1181 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=909d3cdc928cf0cd6b9a19212d4971ab4a3eb232;p=tools%2Flibrpm-tizen.git Eliminate last three assert()'s from the backend - We can trivially handle these "can't happen" cases as EINVAL returns instead of blowing up, do so. --- diff --git a/lib/backend/db3.c b/lib/backend/db3.c index 5b6a826..11ab50d 100644 --- a/lib/backend/db3.c +++ b/lib/backend/db3.c @@ -279,10 +279,10 @@ dbiCursor dbiCursorFree(dbiCursor dbc) int dbiCursorPut(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags) { int rc = EINVAL; + int sane = (key->data != NULL && key->size > 0 && + data->data != NULL && data->size > 0); - assert(key->data != NULL && key->size > 0 && data->data != NULL && data->size > 0); - - if (dbc) { + if (dbc && sane) { DBC * cursor = dbc->cursor; rpmdb rdb = dbc->dbi->dbi_rpmdb; rpmswEnter(&rdb->db_putops, (ssize_t) 0); @@ -298,10 +298,9 @@ int dbiCursorPut(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags) int dbiCursorGet(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags) { int rc = EINVAL; + int sane = ((flags == DB_NEXT) || (key->data != NULL && key->size > 0)); - assert((flags == DB_NEXT) || (key->data != NULL && key->size > 0)); - - if (dbc) { + if (dbc && sane) { DBC * cursor = dbc->cursor; rpmdb rdb = dbc->dbi->dbi_rpmdb; int _printit; @@ -321,10 +320,9 @@ int dbiCursorGet(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags) int dbiCursorDel(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags) { int rc = EINVAL; + int sane = (key->data != NULL && key->size > 0); - assert(key->data != NULL && key->size > 0); - - if (dbc) { + if (dbc && sane) { DBC * cursor = dbc->cursor; int _printit; rpmdb rdb = dbc->dbi->dbi_rpmdb;