Reset return values to zero + NULL's on not found in hash GetEntry()
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 7 Nov 2008 10:03:54 +0000 (12:03 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 7 Nov 2008 10:11:27 +0000 (12:11 +0200)
- avoids having to separately check for return value in some cases and
  accidents from not resetting the values in caller
- in line with headerGet() behavior

lib/rpmhash.C

index a32a7d4..a631074 100644 (file)
@@ -136,18 +136,16 @@ int HASHPREFIX(GetEntry)(HASHTYPE ht, HTKEYTYPE key, HTDATATYPE** data,
               int * dataCount, HTKEYTYPE* tableKey)
 {
     Bucket b;
-
-    if ((b = HASHPREFIX(findEntry)(ht, key)) == NULL)
-       return 0;
+    int rc = ((b = HASHPREFIX(findEntry)(ht, key)) != NULL);
 
     if (data)
-       *data = b->data;
+       *data = rc ? b->data : NULL;
     if (dataCount)
-       *dataCount = b->dataCount;
+       *dataCount = rc ? b->dataCount : 0;
     if (tableKey)
-       *tableKey = b->key;
+       *tableKey = rc ? b->key : NULL;
 
-    return 1;
+    return rc;
 }
 
 void HASHPREFIX(PrintStats)(HASHTYPE ht) {