Просмотр исходного кода

Merge pull request #51 from fperrad/lint_tests_20150403

Lint tests 20150403
Troy D. Hanson 10 лет назад
Родитель
Сommit
cf2d4d75df

+ 2 - 1
tests/test1.c

@@ -14,7 +14,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<10;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);

+ 6 - 5
tests/test10.c

@@ -15,7 +15,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<1000;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         if (i<10) HASH_ADD_INT(users,id,user);
@@ -31,15 +32,15 @@ int main(int argc,char *argv[]) {
 
     i=9;
     HASH_FIND_INT(users,&i,tmp);
-    printf("%d %s in hh\n", i, (tmp ? "found" : "not found"));
+    printf("%d %s in hh\n", i, (tmp != NULL) ? "found" : "not found");
     HASH_FIND(alth,altusers,&i,sizeof(int),tmp);
-    printf("%d %s in alth\n", i, (tmp ? "found" : "not found"));
+    printf("%d %s in alth\n", i, (tmp != NULL) ? "found" : "not found");
 
     i=10;
     HASH_FIND_INT(users,&i,tmp);
-    printf("%d %s in hh\n", i, (tmp ? "found" : "not found"));
+    printf("%d %s in hh\n", i, (tmp != NULL) ? "found" : "not found");
     HASH_FIND(alth,altusers,&i,sizeof(int),tmp);
-    printf("%d %s in alth\n", i, (tmp ? "found" : "not found"));
+    printf("%d %s in alth\n", i, (tmp != NULL) ? "found" : "not found");
 
    return 0;
 }

+ 7 - 5
tests/test11.c

@@ -18,7 +18,7 @@ typedef struct name_rec {
     UT_hash_handle hh;
 } name_rec;
 
-int namecmp(void *_a, void *_b) {
+static int namecmp(void *_a, void *_b) {
     name_rec *a = (name_rec*)_a;
     name_rec *b = (name_rec*)_b;
     return strcmp(a->boy_name,b->boy_name);
@@ -29,20 +29,22 @@ int main(int argc,char *argv[]) {
     char linebuf[BUFLEN];
     FILE *file;
 
-    if ( (file = fopen( "test11.dat", "r" )) == NULL ) {
+    file = fopen( "test11.dat", "r" );
+    if (file == NULL) {
         perror("can't open: ");
         exit(-1);
     }
 
     while (fgets(linebuf,BUFLEN,file) != NULL) {
-        if ( (name = (name_rec*)malloc(sizeof(name_rec))) == NULL) exit(-1);
-        strncpy(name->boy_name,linebuf,BUFLEN);
+        name = (name_rec*)malloc(sizeof(name_rec));
+        if (name == NULL) exit(-1);
+        strncpy(name->boy_name,linebuf,sizeof(name->boy_name));
         HASH_ADD_STR(names,boy_name,name);
     }
 
     fclose(file);
     HASH_SORT(names,namecmp);
-    for(name=names;name;name=(name_rec*)(name->hh.next))
+    for(name=names; name!=NULL; name=(name_rec*)(name->hh.next))
       printf("%s",name->boy_name);
 
    return 0;

+ 6 - 5
tests/test12.c

@@ -15,17 +15,18 @@ int main(int argc, char*argv[]) {
                       "gil", "buck", "ted", NULL };
     int id=0;
 
-    for(name=names; *name; name++) {
-        if ( (person = (person_t*)malloc(sizeof(person_t))) == NULL) exit(-1);
-        strncpy(person->first_name, *name,10);
+    for(name=names; *name != NULL; name++) {
+        person = (person_t*)malloc(sizeof(person_t));
+        if (person == NULL) exit(-1);
+        strncpy(person->first_name, *name,10UL);
         person->id = id++;
         HASH_ADD_STR(people,first_name,person);
         printf("added %s (id %d)\n", person->first_name, person->id);
     }
 
-    for(name=names; *name; name++) {
+    for(name=names; *name != NULL; name++) {
         HASH_FIND_STR(people,*name,person);
-        if (person)
+        if (person != NULL)
             printf("found %s (id %d)\n", person->first_name, person->id);
         else
             printf("failed to find %s\n", *name);

+ 5 - 4
tests/test13.c

@@ -14,7 +14,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<10;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);
@@ -23,7 +24,7 @@ int main(int argc,char *argv[]) {
     /* delete each even ID */
     for(i=0;i<10;i+=2) {
         HASH_FIND_INT(users,&i,tmp);
-        if (tmp) {
+        if (tmp != NULL) {
             HASH_DEL(users,tmp);
             free(tmp);
         } else printf("user id %d not found\n", i);
@@ -31,8 +32,8 @@ int main(int argc,char *argv[]) {
 
     i=9;
     HASH_FIND_INT(users,&i,tmp);
-    if (tmp) {
-        while(tmp) {
+    if (tmp != NULL) {
+        while (tmp != NULL) {
             printf("id %d, following prev...\n", tmp->id);
             tmp = (example_user_t*)tmp->hh.prev;
         }

+ 6 - 4
tests/test14.c

@@ -20,19 +20,21 @@ int main(int argc,char *argv[]) {
     FILE *file;
     int i=0,j=0;
 
-    if ( (file = fopen( "test14.dat", "r" )) == NULL ) {
+    file = fopen( "test14.dat", "r" );
+    if (file == NULL ) {
         perror("can't open: ");
         exit(-1);
     }
 
     while (fgets(linebuf,BUFLEN,file) != NULL) {
         i++;
-        if ( (name = (name_rec*)malloc(sizeof(name_rec))) == NULL) exit(-1);
-        strncpy(name->boy_name,linebuf,BUFLEN);
+        name = (name_rec*)malloc(sizeof(name_rec));
+        if (name == NULL) exit(-1);
+        strncpy(name->boy_name,linebuf,sizeof(name->boy_name));
         HASH_ADD_STR(names,boy_name,name);
     }
 
-    fseek(file,0,SEEK_SET);
+    fseek(file,0L,SEEK_SET);
 
     while (fgets(linebuf,BUFLEN,file) != NULL) {
         HASH_FIND_STR(names,linebuf,name);

+ 3 - 2
tests/test15.c

@@ -17,13 +17,14 @@ int main(int argc, char *argv[]) {
 
     for (n = names; *n != NULL; n++) {
         s = (struct my_struct*)malloc(sizeof(struct my_struct));
-        strncpy(s->name, *n,10);
+        if (s == NULL) exit(-1);
+        strncpy(s->name, *n,10UL);
         s->id = i++;
         HASH_ADD_STR( users, name, s );
     }
 
     HASH_FIND_STR( users, "betty", s);
-    if (s) printf("betty's id is %d\n", s->id);
+    if (s != NULL) printf("betty's id is %d\n", s->id);
 
     /* free the hash table contents */
     HASH_ITER(hh, users, s, tmp) {

+ 4 - 2
tests/test16.c

@@ -19,13 +19,15 @@ struct my_event {
 
 int main(int argc, char *argv[]) {
     struct my_event *e, ev, *events = NULL;
-    unsigned i, keylen;
+    unsigned keylen;
+    int i;
 
     keylen =   offsetof(struct my_event, event_code) + sizeof(char)
              - offsetof(struct my_event, is);
 
     for(i = 0; i < 10; i++) {
         e = (struct my_event*)malloc(sizeof(struct my_event));
+        if (e == NULL) exit(-1);
         memset(e,0,sizeof(struct my_event));
         e->is.a = i * (60*60*24*365);          /* i years (sec)*/
         e->is.b = 0;
@@ -41,6 +43,6 @@ int main(int argc, char *argv[]) {
     ev.is.b = 0;
     ev.event_code = 'b';
     HASH_FIND( hh, events, &ev.is, keylen , e);
-    if (e) printf("found: user %d, unix time %d\n", e->user_id, e->is.a);
+    if (e != NULL) printf("found: user %d, unix time %d\n", e->user_id, e->is.a);
    return 0;
 }

+ 5 - 3
tests/test17.c

@@ -8,7 +8,7 @@ typedef struct example_user_t {
     UT_hash_handle hh;
 } example_user_t;
 
-int rev(void *_a, void *_b) {
+static int rev(void *_a, void *_b) {
     example_user_t *a = (example_user_t*)_a;
     example_user_t *b = (example_user_t*)_b;
     printf("called for a:%d, b:%d\n",a->id, b->id);
@@ -21,7 +21,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=9;i>=0;i--) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);
@@ -38,7 +39,8 @@ int main(int argc,char *argv[]) {
 
     printf("adding 10-20\n");
     for(i=20;i>=10;i--) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);

+ 3 - 2
tests/test18.c

@@ -14,7 +14,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<10;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);
@@ -25,7 +26,7 @@ int main(int argc,char *argv[]) {
     }
 
     /* delete them all, pathologically */
-    while(users) {
+    while(users != NULL) {
       printf("deleting id %i\n", users->id);
       HASH_DEL(users,users); /* single head/deletee var! */
     }

+ 6 - 5
tests/test19.c

@@ -9,14 +9,14 @@ typedef struct example_user_t {
     UT_hash_handle alth;
 } example_user_t;
 
-int ascending_sort(void *_a, void *_b) {
+static int ascending_sort(void *_a, void *_b) {
     example_user_t *a = (example_user_t*)_a;
     example_user_t *b = (example_user_t*)_b;
     if (a->id == b->id) return 0;
     return (a->id < b->id) ? -1 : 1;
 }
 
-int descending_sort(void *_a, void *_b) {
+static int descending_sort(void *_a, void *_b) {
     example_user_t *a = (example_user_t*)_a;
     example_user_t *b = (example_user_t*)_b;
     if (a->id == b->id) return 0;
@@ -29,7 +29,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<1000;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         if (i<10) HASH_ADD_INT(users,id,user);
@@ -38,12 +39,12 @@ int main(int argc,char *argv[]) {
 
     printf("sorting users ascending\n");
     HASH_SRT(hh,users,ascending_sort);
-    for(user=users; user; user=(example_user_t*)user->hh.next)
+    for(user=users; user!=NULL; user=(example_user_t*)user->hh.next)
       printf("user %d\n", user->id);
 
     printf("sorting altusers descending\n");
     HASH_SRT(alth,altusers,descending_sort);
-    for(user=altusers; user; user=(example_user_t*)user->alth.next)
+    for(user=altusers; user!=NULL; user=(example_user_t*)user->alth.next)
       printf("altuser %d\n", user->id);
 
     /* HASH_FSCK(hh,users); */

+ 3 - 2
tests/test2.c

@@ -15,7 +15,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<10;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);
@@ -24,7 +25,7 @@ int main(int argc,char *argv[]) {
     /* find each even ID */
     for(i=0;i<10;i+=2) {
         HASH_FIND_INT(users,&i,tmp);
-        if (tmp) printf("user id %d found, cookie %d\n", tmp->id, tmp->cookie);
+        if (tmp != NULL) printf("user id %d found, cookie %d\n", tmp->id, tmp->cookie);
         else printf("user id %d not found\n", i);
     }
    return 0;

+ 4 - 3
tests/test20.c

@@ -11,10 +11,11 @@ struct my_struct {
 
 int main(int argc, char *argv[]) {
     struct my_struct *s, *t, *bins = NULL;
-    char binary[5] = {3,1,4,1,6};
+    char binary[5] = {'\3','\1','\4','\1','\6'};
 
     /* allocate our structure. initialize to some values */
-    s = (struct my_struct*)calloc(1,sizeof(struct my_struct));
+    s = (struct my_struct*)calloc(1UL,sizeof(struct my_struct));
+    if (s == NULL) exit(-1);
     memcpy(s->bkey, binary, sizeof(binary));
 
     /* add to hash table using general macro */
@@ -23,6 +24,6 @@ int main(int argc, char *argv[]) {
     /* look up the structure we just added */
     HASH_FIND( hh, bins, binary, sizeof(binary), t );
 
-    if (t) printf("found\n");
+    if (t != NULL) printf("found\n");
    return 0;
 }

+ 2 - 1
tests/test21.c

@@ -17,6 +17,7 @@ int main(int argc, char *argv[]) {
     record_t l, *p, *r, *tmp, *records = NULL;
 
     r = (record_t*)malloc( sizeof(record_t) );
+    if (r == NULL) exit(-1);
     memset(r, 0, sizeof(record_t));
     r->key.a = 'a';
     r->key.b = 1;
@@ -27,7 +28,7 @@ int main(int argc, char *argv[]) {
     l.key.b = 1;
     HASH_FIND(hh, records, &l.key, sizeof(record_key_t), p);
 
-    if (p) printf("found %c %d\n", p->key.a, p->key.b);
+    if (p != NULL) printf("found %c %d\n", p->key.a, p->key.b);
 
     HASH_ITER(hh, records, p, tmp) {
       HASH_DEL(records, p);

+ 5 - 3
tests/test22.c

@@ -4,11 +4,11 @@
 #include <string.h>    /* memset       */
 #include "uthash.h"
 
-#define UTF32 1
+#define UTF32 '\x1'
 
 typedef struct {
   UT_hash_handle hh;
-  int len;
+  size_t len;
   char encoding;      /* these two fields */
   int text[];         /* comprise the key */
 } msg_t;
@@ -27,6 +27,7 @@ int main(int argc, char *argv[]) {
 
     /* allocate and initialize our structure */
     msg = (msg_t*)malloc( sizeof(msg_t) + sizeof(beijing) );
+    if (msg == NULL) exit(-1);
     memset(msg, 0, sizeof(msg_t)+sizeof(beijing)); /* zero fill */
     msg->len = sizeof(beijing);
     msg->encoding = UTF32;
@@ -44,11 +45,12 @@ int main(int argc, char *argv[]) {
     msg=NULL;
 
     lookup_key = (lookup_key_t*)malloc(sizeof(*lookup_key) + sizeof(beijing));
+    if (lookup_key == NULL) exit(-1);
     memset(lookup_key, 0, sizeof(*lookup_key) + sizeof(beijing));
     lookup_key->encoding = UTF32;
     memcpy(lookup_key->text, beijing, sizeof(beijing));
     HASH_FIND( hh, msgs, &lookup_key->encoding, keylen, msg );
-    if (msg) printf("found \n");
+    if (msg != NULL) printf("found \n");
     free(lookup_key);
 
     HASH_ITER(hh, msgs, msg, tmp) {

+ 6 - 3
tests/test23.c

@@ -15,25 +15,28 @@ int main() {
   /* first item */
   k = 12345;
   i = (item*)malloc(sizeof(item));
+  if (i == NULL) exit(-1);
   i->key = k; i->data = 0;
   HASH_ADD_INT(items,key,i);
 
   /* second item */
   k = 6789;
   i = (item*)malloc(sizeof(item));
+  if (i == NULL) exit(-1);
   i->key = k; i->data = 0;
   HASH_ADD_INT(items,key,i);
 
   /* third item */
   k = 98765;
   i = (item*)malloc(sizeof(item));
+  if (i == NULL) exit(-1);
   i->key = k; i->data = 0;
   HASH_ADD_INT(items,key,i);
 
   /* look them all up */
-  k = 12345; HASH_FIND_INT(items, &k, j); if (j) printf("found %d\n",k);
-  k = 6789;  HASH_FIND_INT(items, &k, j); if (j) printf("found %d\n",k);
-  k = 98765; HASH_FIND_INT(items, &k, j); if (j) printf("found %d\n",k);
+  k = 12345; HASH_FIND_INT(items, &k, j); if (j != NULL) printf("found %d\n",k);
+  k = 6789;  HASH_FIND_INT(items, &k, j); if (j != NULL) printf("found %d\n",k);
+  k = 98765; HASH_FIND_INT(items, &k, j); if (j != NULL) printf("found %d\n",k);
 
   /* delete them not the way we prefer but it works */
   for(j=items; j != NULL; j=(item*)j->hh.next) {

+ 3 - 2
tests/test24.c

@@ -14,12 +14,13 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<10;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);
     }
 
-    printf("hash contains %d items\n", HASH_COUNT(users));
+    printf("hash contains %u items\n", HASH_COUNT(users));
    return 0;
 }

+ 2 - 3
tests/test25.c

@@ -6,13 +6,12 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-el *head = NULL;
-
 int main(int argc, char *argv[]) {
     int i;
     int count;
     el els[10], *e;
-    for(i=0;i<10;i++) els[i].id='a'+i;
+    el *head = NULL;
+    for(i=0;i<10;i++) els[i].id=(int)'a'+i;
 
     /* test CDL macros */
     printf("CDL macros\n");

+ 9 - 8
tests/test26.c

@@ -10,36 +10,37 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-int namecmp(void *_a, void *_b) {
+static int namecmp(void *_a, void *_b) {
     el *a = (el*)_a;
     el *b = (el*)_b;
     return strcmp(a->bname,b->bname);
 }
 
-el *head = NULL; /* important- initialize to NULL! */
-
 int main(int argc, char *argv[]) {
     el *name, *elt, *tmp, etmp;
+    el *head = NULL; /* important- initialize to NULL! */
 
     char linebuf[BUFLEN];
     FILE *file;
 
-    if ( (file = fopen( "test11.dat", "r" )) == NULL ) {
+    file = fopen( "test11.dat", "r" );
+    if (file == NULL) {
         perror("can't open: ");
         exit(-1);
     }
 
     while (fgets(linebuf,BUFLEN,file) != NULL) {
-        if ( (name = (el*)malloc(sizeof(el))) == NULL) exit(-1);
-        strncpy(name->bname,linebuf,BUFLEN);
+        name = (el*)malloc(sizeof(el));
+        if (name == NULL) exit(-1);
+        strncpy(name->bname,linebuf,sizeof(name->bname));
         DL_APPEND(head, name);
     }
     DL_SORT(head, namecmp);
     DL_FOREACH(head,elt) printf("%s", elt->bname);
 
-    memcpy(&etmp.bname, "WES\n", 5);
+    memcpy(etmp.bname, "WES\n", 5UL);
     DL_SEARCH(head,elt,&etmp,namecmp);
-    if (elt) printf("found %s\n", elt->bname);
+    if (elt != NULL) printf("found %s\n", elt->bname);
 
     /* now delete each element, use the safe iterator */
     DL_FOREACH_SAFE(head,elt,tmp) {

+ 2 - 3
tests/test27.c

@@ -6,12 +6,11 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-el *head = NULL;
-
 int main(int argc, char *argv[]) {
     int i;
     el els[10], *e;
-    for(i=0;i<10;i++) els[i].id='a'+i;
+    el *head = NULL;
+    for(i=0;i<10;i++) els[i].id=(int)'a'+i;
 
     /* test CDL macros */
     printf("CDL macros\n");

+ 2 - 3
tests/test28.c

@@ -6,12 +6,11 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-el *head = NULL;
-
 int main(int argc, char *argv[]) {
     int i;
     el els[10], *e;
-    for(i=0;i<10;i++) els[i].id='a'+i;
+    el *head = NULL;
+    for(i=0;i<10;i++) els[i].id=(int)'a'+i;
 
     /* test CDL macros */
     printf("CDL macros\n");

+ 7 - 6
tests/test29.c

@@ -10,28 +10,29 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-int namecmp(void *_a, void *_b) {
+static int namecmp(void *_a, void *_b) {
     el *a = (el*)_a;
     el *b = (el*)_b;
     return strcmp(a->bname,b->bname);
 }
 
-el *head = NULL;
-
 int main(int argc, char *argv[]) {
     el *name, *tmp;
+    el *head = NULL;
 
     char linebuf[BUFLEN];
     FILE *file;
 
-    if ( (file = fopen( "test11.dat", "r" )) == NULL ) {
+    file = fopen( "test11.dat", "r" );
+    if (file == NULL) {
         perror("can't open: ");
         exit(-1);
     }
 
     while (fgets(linebuf,BUFLEN,file) != NULL) {
-        if ( (name = (el*)malloc(sizeof(el))) == NULL) exit(-1);
-        strncpy(name->bname,linebuf,BUFLEN);
+        name = (el*)malloc(sizeof(el));
+        if (name == NULL) exit(-1);
+        strncpy(name->bname,linebuf,sizeof(name->bname));
         DL_APPEND(head, name);
     }
     DL_SORT(head, namecmp);

+ 3 - 3
tests/test3.c

@@ -14,8 +14,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<10;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL)
-           exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);
@@ -24,7 +24,7 @@ int main(int argc,char *argv[]) {
     /* delete each even ID */
     for(i=0;i<10;i+=2) {
         HASH_FIND_INT(users,&i,tmp);
-        if (tmp) {
+        if (tmp != NULL) {
             HASH_DEL(users,tmp);
             free(tmp);
         } else printf("user id %d not found\n", i);

+ 7 - 6
tests/test30.c

@@ -10,28 +10,29 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-int namecmp(void *_a, void *_b) {
+static int namecmp(void *_a, void *_b) {
     el *a = (el*)_a;
     el *b = (el*)_b;
     return strcmp(a->bname,b->bname);
 }
 
-el *head = NULL;
-
 int main(int argc, char *argv[]) {
     el *name, *tmp;
+    el *head = NULL;
 
     char linebuf[BUFLEN];
     FILE *file;
 
-    if ( (file = fopen( "test11.dat", "r" )) == NULL ) {
+    file = fopen( "test11.dat", "r" );
+    if (file == NULL) {
         perror("can't open: ");
         exit(-1);
     }
 
     while (fgets(linebuf,BUFLEN,file) != NULL) {
-        if ( (name = (el*)malloc(sizeof(el))) == NULL) exit(-1);
-        strncpy(name->bname,linebuf,BUFLEN);
+        name = (el*)malloc(sizeof(el));
+        if (name == NULL) exit(-1);
+        strncpy(name->bname,linebuf,sizeof(name->bname));
         CDL_PREPEND(head, name);
     }
     CDL_SORT(head, namecmp);

+ 7 - 6
tests/test31.c

@@ -10,28 +10,29 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-int namecmp(void *_a, void *_b) {
+static int namecmp(void *_a, void *_b) {
     el *a = (el*)_a;
     el *b = (el*)_b;
     return strcmp(a->bname,b->bname);
 }
 
-el *head = NULL;
-
 int main(int argc, char *argv[]) {
     el *name, *tmp;
+    el *head = NULL;
 
     char linebuf[BUFLEN];
     FILE *file;
 
-    if ( (file = fopen( "test11.dat", "r" )) == NULL ) {
+    file = fopen( "test11.dat", "r" );
+    if (file == NULL) {
         perror("can't open: ");
         exit(-1);
     }
 
     while (fgets(linebuf,BUFLEN,file) != NULL) {
-        if ( (name = (el*)malloc(sizeof(el))) == NULL) exit(-1);
-        strncpy(name->bname,linebuf,BUFLEN);
+        name = (el*)malloc(sizeof(el));
+        if (name == NULL) exit(-1);
+        strncpy(name->bname,linebuf,sizeof(name->bname));
         CDL_PREPEND(head, name);
     }
     CDL_SORT(head, namecmp);

+ 7 - 6
tests/test32.c

@@ -10,26 +10,27 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-int namecmp(el *a, el *b) {
+static int namecmp(el *a, el *b) {
     return strcmp(a->bname,b->bname);
 }
 
-el *head = NULL;
-
 int main(int argc, char *argv[]) {
     el *name, *tmp;
+    el *head = NULL;
 
     char linebuf[BUFLEN];
     FILE *file;
 
-    if ( (file = fopen( "test11.dat", "r" )) == NULL ) {
+    file = fopen( "test11.dat", "r" );
+    if (file == NULL) {
         perror("can't open: ");
         exit(-1);
     }
 
     while (fgets(linebuf,BUFLEN,file) != NULL) {
-        if ( (name = (el*)malloc(sizeof(el))) == NULL) exit(-1);
-        strncpy(name->bname,linebuf,BUFLEN);
+        name = (el*)malloc(sizeof(el));
+        if (name == NULL) exit(-1);
+        strncpy(name->bname,linebuf,sizeof(name->bname));
         DL_PREPEND(head, name);
     }
     /* DL_SORT(head, namecmp); */

+ 7 - 6
tests/test33.c

@@ -10,28 +10,29 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-int namecmp(void *_a, void *_b) {
+static int namecmp(void *_a, void *_b) {
     el *a = (el*)_a;
     el *b = (el*)_b;
     return strcmp(a->bname,b->bname);
 }
 
-el *head = NULL;
-
 int main(int argc, char *argv[]) {
     el *name, *tmp;
+    el *head = NULL;
 
     char linebuf[BUFLEN];
     FILE *file;
 
-    if ( (file = fopen( "test11.dat", "r" )) == NULL ) {
+    file = fopen( "test11.dat", "r" );
+    if (file == NULL) {
         perror("can't open: ");
         exit(-1);
     }
 
     while (fgets(linebuf,BUFLEN,file) != NULL) {
-        if ( (name = (el*)malloc(sizeof(el))) == NULL) exit(-1);
-        strncpy(name->bname,linebuf,BUFLEN);
+        name = (el*)malloc(sizeof(el));
+        if (name == NULL) exit(-1);
+        strncpy(name->bname,linebuf,sizeof(name->bname));
         LL_PREPEND(head, name);
     }
     LL_SORT(head, namecmp);

+ 7 - 6
tests/test34.c

@@ -10,26 +10,27 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-int namecmp(el *a, el *b) {
+static int namecmp(el *a, el *b) {
     return strcmp(a->bname,b->bname);
 }
 
-el *head = NULL;
-
 int main(int argc, char *argv[]) {
     el *name, *tmp;
+    el *head = NULL;
 
     char linebuf[BUFLEN];
     FILE *file;
 
-    if ( (file = fopen( "test11.dat", "r" )) == NULL ) {
+    file = fopen( "test11.dat", "r" );
+    if (file == NULL) {
         perror("can't open: ");
         exit(-1);
     }
 
     while (fgets(linebuf,BUFLEN,file) != NULL) {
-        if ( (name = (el*)malloc(sizeof(el))) == NULL) exit(-1);
-        strncpy(name->bname,linebuf,BUFLEN);
+        name = (el*)malloc(sizeof(el));
+        if (name == NULL) exit(-1);
+        strncpy(name->bname,linebuf,sizeof(name->bname));
         CDL_PREPEND(head, name);
     }
     /* CDL_SORT(head, namecmp); */

+ 6 - 6
tests/test35.c

@@ -14,20 +14,20 @@ int main(int argc,char *argv[]) {
     elt elts[10];
     char label[6];
     for(i=0;i<10;i++) {
-      elts[i].s = (char*)malloc(6);
-      strncpy(elts[i].s, "hello",6);
+      elts[i].s = (char*)malloc(6UL);
+      strncpy(elts[i].s, "hello",6UL);
       elts[i].s[0] = 'a' + i;
       printf("%d: %s\n", i, elts[i].s);
-      HASH_ADD_KEYPTR(hh, head, elts[i].s, 6, &elts[i]);
+      HASH_ADD_KEYPTR(hh, head, elts[i].s, 6UL, &elts[i]);
     }
 
     /* look up each element and verify the result pointer */
-    strncpy(label, "hello", 6);
+    strncpy(label, "hello", sizeof(label));
     for(i=0;i<10;i++) {
       elt *e;
       label[0] = 'a' + i;
-      HASH_FIND(hh,head,label,6,e);
-      if (e) {
+      HASH_FIND(hh,head,label,6UL,e);
+      if (e != NULL) {
         printf( "found %s\n", e->s);
         printf( "right address? %s\n", (e == &elts[i]) ? "yes" : "no");
       }

+ 6 - 6
tests/test36.c

@@ -8,13 +8,13 @@ typedef struct {
     UT_hash_handle ah;
 } example_user_t;
 
-#define EVENS(x) (((x)->id & 1) == 0)
-int evens(void *userv) {
+#define EVENS(x) (((x)->id % 2) == 0)
+static int evens(void *userv) {
   example_user_t *user = (example_user_t*)userv;
-  return ((user->id & 1) ? 0 : 1);
+  return ((user->id % 2) ? 0 : 1);
 }
 
-int idcmp(void *_a, void *_b) {
+static int idcmp(void *_a, void *_b) {
   example_user_t *a = (example_user_t*)_a;
   example_user_t *b = (example_user_t*)_b;
   return (a->id - b->id);
@@ -31,7 +31,7 @@ int main(int argc,char *argv[]) {
         HASH_ADD_INT(users,id,user);
     }
 
-    for(user=users; user; user=(example_user_t*)(user->hh.next)) {
+    for(user=users; user!=NULL; user=(example_user_t*)(user->hh.next)) {
         printf("user %d\n", user->id);
     }
 
@@ -39,7 +39,7 @@ int main(int argc,char *argv[]) {
     HASH_SELECT(ah,ausers,hh,users,evens);
     HASH_SRT(ah,ausers,idcmp);
 
-    for(user=ausers; user; user=(example_user_t*)(user->ah.next)) {
+    for(user=ausers; user!=NULL; user=(example_user_t*)(user->ah.next)) {
         printf("auser %d\n", user->id);
     }
    return 0;

+ 5 - 5
tests/test37.c

@@ -8,9 +8,9 @@ typedef struct {
     UT_hash_handle ah;
 } example_user_t;
 
-#define EVENS(x) ((((example_user_t*)(x))->id & 1) == 0)
+#define EVENS(x) ((((example_user_t*)(x))->id % 2) == 0)
 
-int idcmp(void *_a, void *_b) {
+static int idcmp(void *_a, void *_b) {
   example_user_t *a = (example_user_t*)_a;
   example_user_t *b = (example_user_t*)_b;
   return (a->id - b->id);
@@ -27,7 +27,7 @@ int main(int argc,char *argv[]) {
         HASH_ADD_INT(users,id,user);
     }
 
-    for(user=users; user; user=(example_user_t*)(user->hh.next)) {
+    for(user=users; user!=NULL; user=(example_user_t*)(user->hh.next)) {
         printf("user %d\n", user->id);
     }
     printf("users count: %u\n", HASH_CNT(hh,users));
@@ -36,14 +36,14 @@ int main(int argc,char *argv[]) {
     HASH_SELECT(ah,ausers,hh,users,EVENS);
     HASH_SRT(ah,ausers,idcmp);
 
-    for(user=ausers; user; user=(example_user_t*)(user->ah.next)) {
+    for(user=ausers; user!=NULL; user=(example_user_t*)(user->ah.next)) {
         printf("auser %d\n", user->id);
     }
     printf("ausers count: %u\n", HASH_CNT(ah,ausers));
     HASH_CLEAR(ah,ausers);
     printf("cleared ausers.\n");
     printf("ausers count: %u\n", HASH_CNT(ah,ausers));
-    for(user=ausers; user; user=(example_user_t*)(user->ah.next)) {
+    for(user=ausers; user!=NULL; user=(example_user_t*)(user->ah.next)) {
         printf("auser %d\n", user->id);
     }
     printf("users count: %u\n", HASH_CNT(hh,users));

+ 3 - 3
tests/test38.c

@@ -7,16 +7,16 @@ struct test_t {
   UT_hash_handle hh;
 };
 
-struct test_t *tests=NULL, *test;
-
 int main(void) {
+  struct test_t *tests=NULL, *test;
   int a, b;
   for (b=0; b < 3; b++) {
     for (a=0; a < 10; a++) {
       test = NULL;
       HASH_FIND(hh, tests, &a, sizeof(a), test);
-      if (! test) {
+      if (test == NULL) {
         test = (struct test_t*)malloc(sizeof(struct test_t));
+        if (test == NULL) exit(-1);
         memset(test, 0, sizeof(struct test_t));
         test->a = a;
         HASH_ADD(hh, tests, a, sizeof(a), test);

+ 2 - 3
tests/test39.c

@@ -7,12 +7,11 @@ typedef struct {
   UT_hash_handle hh;
 } ns_t;
 
-ns_t *head = NULL;
-
 int main() {
   const char *keys[] = {"eins", "zwei", "drei"};
   unsigned i;
   ns_t *nsp;
+  ns_t *head = NULL;
 
   for(i=0; i < sizeof(keys)/sizeof(keys[0]); i++) {
     printf("adding key %s\n", keys[i]);
@@ -25,7 +24,7 @@ int main() {
   for(i=0; i < sizeof(keys)/sizeof(keys[0]); i++) {
     printf("looking for key %s... ", keys[i]);
     HASH_FIND(hh,head,keys[i],strlen(keys[i]),nsp);
-    printf("%s.\n", (nsp?"found":"not found"));
+    printf("%s.\n", (nsp!=NULL)?"found":"not found");
   }
   return 0;
 }

+ 2 - 1
tests/test4.c

@@ -15,7 +15,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<10;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);

+ 1 - 2
tests/test41.c

@@ -6,10 +6,9 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-el *head = NULL;
-
 int main(int argc, char *argv[]) {
     int i;
+    el *head = NULL;
     el els[10], *e, *tmp, *tmp2;
     for(i=0;i<10;i++) els[i].id='a'+i;
 

+ 2 - 3
tests/test42.c

@@ -6,12 +6,11 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-el *head = NULL;
-
-int eltcmp(el *a, el *b) {return a->id - b->id;}
+static int eltcmp(el *a, el *b) {return a->id - b->id;}
 
 int main(int argc, char *argv[]) {
     int i;
+    el *head = NULL;
     el els[10], *e, *tmp, *tmp2;
     for(i=0;i<10;i++) els[i].id='a'+i;
 

+ 1 - 1
tests/test44.c

@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include "utarray.h"
 
-int reverse(const void *a,const void*b) {
+static int reverse(const void *a,const void*b) {
     int _a = *(int*)a;
     int _b = *(int*)b;
     return _b - _a;

+ 2 - 2
tests/test46.c

@@ -1,13 +1,13 @@
 #include <stdio.h>
 #include "utarray.h"
 
-int strsort(const void *_a, const void *_b) {
+static int strsort(const void *_a, const void *_b) {
   char *a = *(char**)_a;
   char *b = *(char**)_b;
   return strcmp(a,b);
 }
 
-int revsort(const void *_a, const void *_b) {
+static int revsort(const void *_a, const void *_b) {
   char *a = *(char**)_a;
   char *b = *(char**)_b;
   return strcmp(b,a);

+ 3 - 2
tests/test5.c

@@ -15,7 +15,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<10;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);
@@ -26,7 +27,7 @@ int main(int argc,char *argv[]) {
     for(i=0;i<10;i+=2) {
         j=i*i;
         HASH_FIND(alth,altusers,&j,sizeof(int),tmp);
-        if (tmp) printf("cookie %d found, user id %d\n", tmp->cookie, tmp->id);
+        if (tmp != NULL) printf("cookie %d found, user id %d\n", tmp->cookie, tmp->id);
         else printf("cookie %d not found\n", j);
     }
    return 0;

+ 2 - 2
tests/test52.c

@@ -7,13 +7,13 @@ typedef struct {
     char *s;
 } intchar_t;
 
-void intchar_copy(void *_dst, const void *_src) {
+static void intchar_copy(void *_dst, const void *_src) {
   intchar_t *dst = (intchar_t*)_dst, *src = (intchar_t*)_src;
   dst->a = src->a;
   dst->s = src->s ? strdup(src->s) : NULL;
 }
 
-void intchar_dtor(void *_elt) {
+static void intchar_dtor(void *_elt) {
   intchar_t *elt = (intchar_t*)_elt;
   if (elt->s) free(elt->s);
 }

+ 9 - 7
tests/test56.c

@@ -18,18 +18,17 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-int namecmp(void *_a, void *_b) {
+static int namecmp(void *_a, void *_b) {
     el *a = (el*)_a;
     el *b = (el*)_b;
     return strcmp(a->bname,b->bname);
 }
 
-el *head = NULL; /* important- initialize to NULL! */
-
 int main(int argc, char *argv[]) {
     el *name, *elt, *tmp, etmp;
     int i;
     example_user_t *user, *users=NULL;
+    el *head = NULL; /* important- initialize to NULL! */
 
     char linebuf[BUFLEN];
     FILE *file;
@@ -37,14 +36,16 @@ int main(int argc, char *argv[]) {
     UT_string *s;
     char binary[] = "\xff\xff";
 
-    if ( (file = fopen( "test11.dat", "r" )) == NULL ) {
+    file = fopen( "test11.dat", "r" );
+    if (file == NULL) {
         perror("can't open: ");
         exit(-1);
     }
 
     while (fgets(linebuf,BUFLEN,file) != NULL) {
-        if ( (name = (el*)malloc(sizeof(el))) == NULL) exit(-1);
-        strncpy(name->bname,linebuf,BUFLEN);
+        name = (el*)malloc(sizeof(el));
+        if (name == NULL) exit(-1);
+        strncpy(name->bname,linebuf,sizeof(name->bname));
         DL_APPEND(head, name);
     }
     DL_SORT(head, namecmp);
@@ -63,7 +64,8 @@ int main(int argc, char *argv[]) {
 
     /* create elements */
     for(i=0;i<10;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);

+ 5 - 4
tests/test6.c

@@ -14,11 +14,11 @@ typedef struct example_user_t {
     UT_hash_handle hh;
 } example_user_t;
 
-void *alt_malloc(size_t sz) {
+static void *alt_malloc(size_t sz) {
     if (sz == sizeof(UT_hash_table)) printf("%s\n", "alt malloc table");
     return malloc(sz);
 }
-void alt_free(void *ptr) {
+static void alt_free(void *ptr) {
     /* printf("%s\n", "alt_free"); */
     free(ptr);
 }
@@ -29,7 +29,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<10;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);
@@ -38,7 +39,7 @@ int main(int argc,char *argv[]) {
     /* delete each ID */
     for(i=0;i<10;i++) {
         HASH_FIND_INT(users,&i,tmp);
-        if (tmp) {
+        if (tmp != NULL) {
             HASH_DEL(users,tmp);
             free(tmp);
         } else printf("user id %d not found\n", i);

+ 1 - 1
tests/test61.c

@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include "utarray.h"
 
-int strsort(const void *_a, const void *_b) {
+static int strsort(const void *_a, const void *_b) {
   char *a = *(char**)_a;
   char *b = *(char**)_b;
   return strcmp(a,b);

+ 4 - 3
tests/test65.c

@@ -16,7 +16,7 @@ struct CacheEntry {
 };
 struct CacheEntry *cache = NULL;
 
-char * /*value*/ find_in_cache(char *key)
+static char * /*value*/ find_in_cache(char *key)
 {
     struct CacheEntry *entry;
     HASH_FIND_STR(cache, key, entry);
@@ -29,7 +29,7 @@ char * /*value*/ find_in_cache(char *key)
     return NULL;
 }
 
-void add_to_cache(char *key, char *value)
+static void add_to_cache(char *key, char *value)
 {
     struct CacheEntry *entry, *tmp_entry;
     entry = malloc(sizeof(struct CacheEntry));
@@ -57,7 +57,8 @@ int main(int argc, char *argv[]) {
   FILE *file;
   int i=0;
 
-  if ( (file = fopen( "test65.dat", "r" )) == NULL ) {
+  file = fopen( "test65.dat", "r" );
+  if (file == NULL) {
       perror("can't open: ");
       exit(-1);
   }

+ 2 - 1
tests/test66.c

@@ -16,7 +16,8 @@ int main(int argc, char*argv[]) {
     int id=0;
 
     for(name=names; *name; name++) {
-        if ( (person = (person_t*)malloc(sizeof(person_t))) == NULL) exit(-1);
+        person = (person_t*)malloc(sizeof(person_t));
+        if (person == NULL) exit(-1);
         strncpy(person->first_name, *name,10);
         person->id = id++;
         HASH_ADD_STR(people,first_name,person);

+ 3 - 2
tests/test7.c

@@ -15,7 +15,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<1000;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);
@@ -24,7 +25,7 @@ int main(int argc,char *argv[]) {
     /* delete each ID */
     for(i=0;i<1000;i++) {
         HASH_FIND_INT(users,&i,tmp);
-        if (tmp) {
+        if (tmp != NULL) {
             HASH_DEL(users,tmp);
             free(tmp);
         } else printf("user id %d not found\n", i);

+ 5 - 4
tests/test8.c

@@ -14,20 +14,21 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<10;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);
-        printf("num_items in hash: %d\n", user->hh.tbl->num_items);
+        printf("num_items in hash: %u\n", user->hh.tbl->num_items);
     }
 
     /* delete each even ID */
     for(i=0;i<10;i+=2) {
         HASH_FIND_INT(users,&i,tmp);
-        if (tmp) {
+        if (tmp != NULL) {
             HASH_DEL(users,tmp);
             free(tmp);
-            printf("deleted; num_items in hash: %d\n", user->hh.tbl->num_items);
+            printf("deleted; num_items in hash: %u\n", user->hh.tbl->num_items);
         } else printf("user id %d not found\n", i);
     }
    return 0;

+ 2 - 1
tests/test83.c

@@ -16,7 +16,8 @@ int main(int argc, char*argv[]) {
     int id=0;
 
     for(name=names; *name; name++) {
-        if ( (person = (person_t*)malloc(sizeof(person_t))) == NULL) exit(-1);
+        person = (person_t*)malloc(sizeof(person_t));
+        if (person == NULL) exit(-1);
         strncpy(person->first_name, *name,10);
         person->id = id++;
         HASH_ADD_STR(people,first_name,person);

+ 2 - 1
tests/test84.c

@@ -16,7 +16,8 @@ int main(int argc, char*argv[]) {
     int id=0;
 
     for(name=names; *name; name++) {
-        if ( (person = (person_t*)malloc(sizeof(person_t))) == NULL) exit(-1);
+        person = (person_t*)malloc(sizeof(person_t));
+        if (person == NULL) exit(-1);
         person->first_name = malloc(10);
         strncpy(person->first_name, *name,10);
         person->id = id++;

+ 2 - 1
tests/test85.c

@@ -14,7 +14,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<10;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);

+ 3 - 2
tests/test9.c

@@ -14,7 +14,8 @@ int main(int argc,char *argv[]) {
 
     /* create elements */
     for(i=0;i<1000;i++) {
-        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
+        user = (example_user_t*)malloc(sizeof(example_user_t));
+        if (user == NULL) exit(-1);
         user->id = i;
         user->cookie = i*i;
         HASH_ADD_INT(users,id,user);
@@ -23,7 +24,7 @@ int main(int argc,char *argv[]) {
     /* delete each ID */
     for(i=0;i<1000;i+=2) {
         HASH_FIND_INT(users,&i,tmp);
-        if (tmp) {
+        if (tmp != NULL) {
             printf("user %d, cookie %d\n", tmp->id, tmp->cookie);
         } else printf("user id %d not found\n", i);
     }