Eliminate the rest of idiotic assert()'s in rpmtd.c
Finish what was started in commit 9c979cffe9
,
with greetings to self ten years ago...
This commit is contained in:
parent
80b5c12eaa
commit
a8abf2cfd0
48
lib/rpmtd.c
48
lib/rpmtd.c
|
@ -84,15 +84,12 @@ rpmtdFlags rpmtdGetFlags(rpmtd td)
|
|||
|
||||
int rpmtdGetIndex(rpmtd td)
|
||||
{
|
||||
assert(td != NULL);
|
||||
return td->ix;
|
||||
return (td != NULL) ? td->ix : -1;
|
||||
}
|
||||
|
||||
int rpmtdSetIndex(rpmtd td, int index)
|
||||
{
|
||||
assert(td != NULL);
|
||||
|
||||
if (index < 0 || index >= rpmtdCount(td)) {
|
||||
if (td == NULL || index < 0 || index >= rpmtdCount(td)) {
|
||||
return -1;
|
||||
}
|
||||
td->ix = index;
|
||||
|
@ -101,7 +98,8 @@ int rpmtdSetIndex(rpmtd td, int index)
|
|||
|
||||
int rpmtdInit(rpmtd td)
|
||||
{
|
||||
assert(td != NULL);
|
||||
if (td == NULL)
|
||||
return -1;
|
||||
|
||||
/* XXX check that this is an array type? */
|
||||
td->ix = -1;
|
||||
|
@ -110,11 +108,9 @@ int rpmtdInit(rpmtd td)
|
|||
|
||||
int rpmtdNext(rpmtd td)
|
||||
{
|
||||
assert(td != NULL);
|
||||
|
||||
int i = -1;
|
||||
|
||||
if (++td->ix >= 0) {
|
||||
if (td != NULL && ++td->ix >= 0) {
|
||||
if (td->ix < rpmtdCount(td)) {
|
||||
i = td->ix;
|
||||
} else {
|
||||
|
@ -126,7 +122,6 @@ int rpmtdNext(rpmtd td)
|
|||
|
||||
uint32_t *rpmtdNextUint32(rpmtd td)
|
||||
{
|
||||
assert(td != NULL);
|
||||
uint32_t *res = NULL;
|
||||
if (rpmtdNext(td) >= 0) {
|
||||
res = rpmtdGetUint32(td);
|
||||
|
@ -136,7 +131,6 @@ uint32_t *rpmtdNextUint32(rpmtd td)
|
|||
|
||||
uint64_t *rpmtdNextUint64(rpmtd td)
|
||||
{
|
||||
assert(td != NULL);
|
||||
uint64_t *res = NULL;
|
||||
if (rpmtdNext(td) >= 0) {
|
||||
res = rpmtdGetUint64(td);
|
||||
|
@ -146,7 +140,6 @@ uint64_t *rpmtdNextUint64(rpmtd td)
|
|||
|
||||
const char *rpmtdNextString(rpmtd td)
|
||||
{
|
||||
assert(td != NULL);
|
||||
const char *res = NULL;
|
||||
if (rpmtdNext(td) >= 0) {
|
||||
res = rpmtdGetString(td);
|
||||
|
@ -158,9 +151,7 @@ char * rpmtdGetChar(rpmtd td)
|
|||
{
|
||||
char *res = NULL;
|
||||
|
||||
assert(td != NULL);
|
||||
|
||||
if (td->type == RPM_CHAR_TYPE) {
|
||||
if (td != NULL && td->type == RPM_CHAR_TYPE) {
|
||||
int ix = (td->ix >= 0 ? td->ix : 0);
|
||||
res = (char *) td->data + ix;
|
||||
}
|
||||
|
@ -170,9 +161,7 @@ uint16_t * rpmtdGetUint16(rpmtd td)
|
|||
{
|
||||
uint16_t *res = NULL;
|
||||
|
||||
assert(td != NULL);
|
||||
|
||||
if (td->type == RPM_INT16_TYPE) {
|
||||
if (td != NULL && td->type == RPM_INT16_TYPE) {
|
||||
int ix = (td->ix >= 0 ? td->ix : 0);
|
||||
res = (uint16_t *) td->data + ix;
|
||||
}
|
||||
|
@ -183,9 +172,7 @@ uint32_t * rpmtdGetUint32(rpmtd td)
|
|||
{
|
||||
uint32_t *res = NULL;
|
||||
|
||||
assert(td != NULL);
|
||||
|
||||
if (td->type == RPM_INT32_TYPE) {
|
||||
if (td != NULL && td->type == RPM_INT32_TYPE) {
|
||||
int ix = (td->ix >= 0 ? td->ix : 0);
|
||||
res = (uint32_t *) td->data + ix;
|
||||
}
|
||||
|
@ -196,9 +183,7 @@ uint64_t * rpmtdGetUint64(rpmtd td)
|
|||
{
|
||||
uint64_t *res = NULL;
|
||||
|
||||
assert(td != NULL);
|
||||
|
||||
if (td->type == RPM_INT64_TYPE) {
|
||||
if (td != NULL && td->type == RPM_INT64_TYPE) {
|
||||
int ix = (td->ix >= 0 ? td->ix : 0);
|
||||
res = (uint64_t *) td->data + ix;
|
||||
}
|
||||
|
@ -209,7 +194,8 @@ const char * rpmtdGetString(rpmtd td)
|
|||
{
|
||||
const char *str = NULL;
|
||||
|
||||
assert(td != NULL);
|
||||
if (td == NULL)
|
||||
return NULL;
|
||||
|
||||
if (td->type == RPM_STRING_TYPE) {
|
||||
str = (const char *) td->data;
|
||||
|
@ -224,10 +210,12 @@ const char * rpmtdGetString(rpmtd td)
|
|||
|
||||
uint64_t rpmtdGetNumber(rpmtd td)
|
||||
{
|
||||
assert(td != NULL);
|
||||
uint64_t val = 0;
|
||||
int ix = (td->ix >= 0 ? td->ix : 0);
|
||||
|
||||
if (td == NULL)
|
||||
return 0;
|
||||
|
||||
switch (td->type) {
|
||||
case RPM_INT64_TYPE:
|
||||
val = *((uint64_t *) td->data + ix);
|
||||
|
@ -269,10 +257,12 @@ char *rpmtdFormat(rpmtd td, rpmtdFormats fmt, const char *errmsg)
|
|||
|
||||
int rpmtdSetTag(rpmtd td, rpmTagVal tag)
|
||||
{
|
||||
assert(td != NULL);
|
||||
rpmTagType newtype = rpmTagGetTagType(tag);
|
||||
int rc = 0;
|
||||
|
||||
if (td == NULL)
|
||||
goto exit;
|
||||
|
||||
/*
|
||||
* Sanity checks:
|
||||
* - is the new tag valid at all
|
||||
|
@ -427,8 +417,10 @@ rpmtd rpmtdDup(rpmtd td)
|
|||
rpmtd newtd = NULL;
|
||||
char **data = NULL;
|
||||
int i;
|
||||
|
||||
if (td == NULL)
|
||||
return NULL;
|
||||
|
||||
assert(td != NULL);
|
||||
/* TODO: permit other types too */
|
||||
if (td->type != RPM_STRING_ARRAY_TYPE && td->type != RPM_I18NSTRING_TYPE) {
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in New Issue