Remove comparisons that can never evaluate to true
authorDan Scott <dan@coffeecode.net>
Sat, 5 May 2012 05:58:22 +0000 (01:58 -0400)
committerDan Scott <dan@coffeecode.net>
Tue, 22 May 2012 05:54:41 +0000 (01:54 -0400)
Using clang as the compiler results in 4 warnings like the following:

osrf_list.c:106:23: warning: comparison of unsigned expression < 0 is
always false [-Wtautological-compare]
        if(!list || position < 0) return NULL;
                    ~~~~~~~~ ^ ~

(Explanation: "position" is an unsigned int; thus the comparison to < 0
can never evaluate to true).

Signed-off-by: Dan Scott <dan@coffeecode.net>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>

src/libopensrf/osrf_list.c

index 7ea3e97..4d4bb11 100644 (file)
@@ -103,7 +103,7 @@ int osrfListPushFirst( osrfList* list, void* item ) {
        calling code.
 */
 void* osrfListSet( osrfList* list, void* item, unsigned int position ) {
-       if(!list || position < 0) return NULL;
+       if(!list) return NULL;
 
        int newsize = list->arrsize;
 
@@ -144,7 +144,7 @@ void* osrfListSet( osrfList* list, void* item, unsigned int position ) {
        If either parameter is invalid, the return value is NULL.
 */
 void* osrfListGetIndex( const osrfList* list, unsigned int position ) {
-       if(!list || position >= list->size || position < 0) return NULL;
+       if(!list || position >= list->size) return NULL;
        return list->arrlist[position];
 }
 
@@ -226,7 +226,7 @@ void osrfListSwap( osrfList* one, osrfList* two ) {
        shift other pointers down to fill in the hole left by the removal.
 */
 void* osrfListRemove( osrfList* list, unsigned int position ) {
-       if(!list || position >= list->size || position < 0) return NULL;
+       if(!list || position >= list->size) return NULL;
 
        void* olditem = list->arrlist[position];
        list->arrlist[position] = NULL;
@@ -249,7 +249,7 @@ void* osrfListRemove( osrfList* list, unsigned int position ) {
        to which the pointer points, even if an item-freeing function has been designated.
 */
 void* osrfListExtract( osrfList* list, unsigned int position ) {
-       if(!list || position >= list->size || position < 0) return NULL;
+       if(!list || position >= list->size) return NULL;
 
        void* olditem = list->arrlist[position];
        list->arrlist[position] = NULL;