Explorar o código

Merge pull request #54 from fperrad/lint_tests_20150414

Lint tests 20150414
Troy D. Hanson %!s(int64=10) %!d(string=hai) anos
pai
achega
faa99f9614

+ 3 - 2
tests/emit_keys.c

@@ -31,8 +31,9 @@ int main(int argc,char *argv[]) {
     }
 
     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);
         i++;
     }

+ 10 - 10
tests/hashscan.c

@@ -76,7 +76,7 @@ int getkeys=0;
 char *hash_fcns[] = {"???","JEN","BER","SFH","SAX","FNV","OAT","MUR"};
 
 /* given a peer key/len/hashv, reverse engineer its hash function */
-int infer_hash_function(char *key, size_t keylen, uint32_t hashv) {
+static int infer_hash_function(char *key, size_t keylen, uint32_t hashv) {
   uint32_t obkt, ohashv, num_bkts=0x01000000; /* anything ok */
   /* BER SAX FNV OAT JEN SFH */
   HASH_JEN(key,keylen,num_bkts,ohashv,obkt); if (ohashv == hashv) return JEN;
@@ -92,7 +92,7 @@ int infer_hash_function(char *key, size_t keylen, uint32_t hashv) {
 
 /* read peer's memory from addr for len bytes, store into our dst */
 #ifdef __FreeBSD__
-int read_mem(void *dst, pid_t pid, void *start, size_t len) {
+static int read_mem(void *dst, pid_t pid, void *start, size_t len) {
   struct ptrace_io_desc io_desc;
   int ret;
 
@@ -114,7 +114,7 @@ int read_mem(void *dst, pid_t pid, void *start, size_t len) {
   return 0;
 }
 #else
-int read_mem(void *dst, int fd, off_t start, size_t len) {
+static int read_mem(void *dst, int fd, off_t start, size_t len) {
   int rc;
   size_t bytes_read=0;
   if (lseek(fd, start, SEEK_SET) == (off_t)-1) {
@@ -132,12 +132,12 @@ int read_mem(void *dst, int fd, off_t start, size_t len) {
 #endif
 
 /* later compensate for possible presence of bloom filter */
-char *tbl_from_sig_addr(char *sig) {
+static char *tbl_from_sig_addr(char *sig) {
   return (sig - offsetof(UT_hash_table,signature));
 }
 
 #define HS_BIT_TEST(v,i) (v[i/8] & (1U << (i%8)))
-void found(int fd, char* peer_sig, pid_t pid) {
+static void found(int fd, char* peer_sig, pid_t pid) {
   UT_hash_table *tbl=NULL;
   UT_hash_bucket *bkts=NULL;
   UT_hash_handle hh;
@@ -338,7 +338,7 @@ Address            items    ideal  buckets mxch/<10 fl bloom/sat fcn keys saved
 
 
 #ifdef __FreeBSD__
-void sigscan(pid_t pid, void *start, void *end, uint32_t sig) {
+static void sigscan(pid_t pid, void *start, void *end, uint32_t sig) {
   struct ptrace_io_desc io_desc;
   int page_size = getpagesize();
   char *buf;
@@ -389,7 +389,7 @@ void sigscan(pid_t pid, void *start, void *end, uint32_t sig) {
   }
 }
 #else
-void sigscan(int fd, off_t start, off_t end, uint32_t sig, pid_t pid) {
+static void sigscan(int fd, off_t start, off_t end, uint32_t sig, pid_t pid) {
   int rlen;
   uint32_t u;
   off_t at=0;
@@ -414,7 +414,7 @@ void sigscan(int fd, off_t start, off_t end, uint32_t sig, pid_t pid) {
 
 
 #ifdef __FreeBSD__
-int scan(pid_t pid) {
+static int scan(pid_t pid) {
   vma_t *vmas=NULL, vma;
   unsigned i, num_vmas = 0;
   int ret;
@@ -486,7 +486,7 @@ die:
   return 0;
 }
 # else
-int scan(pid_t pid) {
+static int scan(pid_t pid) {
   FILE *mapf;
   char mapfile[30], memfile[30], line[100];
   vma_t *vmas=NULL, vma;
@@ -559,7 +559,7 @@ int scan(pid_t pid) {
 #endif
 
 
-void usage(const char *prog) {
+static void usage(const char *prog) {
   fprintf(stderr,"usage: %s [-v] [-k] <pid>\n", prog);
   exit(-1);
 }

+ 31 - 29
tests/keystat.c

@@ -12,7 +12,7 @@
 #define uthash_noexpand_fyi(t) die()
 #define UNALIGNED_KEYS 0
 
-void die() {
+static void die() {
   fprintf(stderr,"expansion inhibited\n");
   exit(-1);
 }
@@ -22,7 +22,7 @@ void die() {
  * gives much more accurate elapsed times under Windows. */
 #if (( defined __CYGWIN__ ) || ( defined __MINGW32__ ))
 #include <windows.h>
-void win_gettimeofday(struct timeval* p, void* tz /* IGNORED */) {
+static void win_gettimeofday(struct timeval* p, void* tz /* IGNORED */) {
   LARGE_INTEGER q;
   static long long freq;
   static long long cyg_timer;
@@ -63,37 +63,37 @@ typedef struct stat_key {
 #define CHAIN_20  3
 #define CHAIN_100 4
 #define CHAIN_MAX 5
-void hash_chain_len_histogram(UT_hash_table *tbl) {
+static void hash_chain_len_histogram(const UT_hash_table *tbl) {
   unsigned i, bkt_hist[CHAIN_MAX+1];
-  double pct = 100.0/tbl->num_buckets;
+  double pct = 100.0/(double)tbl->num_buckets;
   memset(bkt_hist,0,sizeof(bkt_hist));
   for(i=0; i < tbl->num_buckets; i++) {
       unsigned count = tbl->buckets[i].count;
-      if (count == 0) bkt_hist[CHAIN_0]++;
-      else if (count < 5) bkt_hist[CHAIN_5]++;
-      else if (count < 10) bkt_hist[CHAIN_10]++;
-      else if (count < 20) bkt_hist[CHAIN_20]++;
-      else if (count < 100) bkt_hist[CHAIN_100]++;
+      if (count == 0U) bkt_hist[CHAIN_0]++;
+      else if (count < 5U) bkt_hist[CHAIN_5]++;
+      else if (count < 10U) bkt_hist[CHAIN_10]++;
+      else if (count < 20U) bkt_hist[CHAIN_20]++;
+      else if (count < 100U) bkt_hist[CHAIN_100]++;
       else bkt_hist[CHAIN_MAX]++;
   }
-  fprintf(stderr, "Buckets with     0 items: %.1f%%\n", bkt_hist[CHAIN_0 ]*pct);
-  fprintf(stderr, "Buckets with <   5 items: %.1f%%\n", bkt_hist[CHAIN_5 ]*pct);
-  fprintf(stderr, "Buckets with <  10 items: %.1f%%\n", bkt_hist[CHAIN_10]*pct);
-  fprintf(stderr, "Buckets with <  20 items: %.1f%%\n", bkt_hist[CHAIN_20]*pct);
-  fprintf(stderr, "Buckets with < 100 items: %.1f%%\n", bkt_hist[CHAIN_100]*pct);
-  fprintf(stderr, "Buckets with > 100 items: %.1f%%\n", bkt_hist[CHAIN_MAX]*pct);
+  fprintf(stderr, "Buckets with     0 items: %.1f%%\n", (double)bkt_hist[CHAIN_0 ]*pct);
+  fprintf(stderr, "Buckets with <   5 items: %.1f%%\n", (double)bkt_hist[CHAIN_5 ]*pct);
+  fprintf(stderr, "Buckets with <  10 items: %.1f%%\n", (double)bkt_hist[CHAIN_10]*pct);
+  fprintf(stderr, "Buckets with <  20 items: %.1f%%\n", (double)bkt_hist[CHAIN_20]*pct);
+  fprintf(stderr, "Buckets with < 100 items: %.1f%%\n", (double)bkt_hist[CHAIN_100]*pct);
+  fprintf(stderr, "Buckets with > 100 items: %.1f%%\n", (double)bkt_hist[CHAIN_MAX]*pct);
 }
 
 int main(int argc, char *argv[]) {
-    int dups=0, rc, fd, done=0, err=0, want, i=0, padding=0, v=1, percent=100;
+    int dups=0, rc, fd, done=0, err=0, want, i, padding=0, v=1, percent=100;
     unsigned keylen, max_keylen=0, verbose=0;
     const char *filename = "/dev/stdin";
     char *dst;
     stat_key *keyt, *keytmp, *keys=NULL, *keys2=NULL;
     struct timeval start_tm, end_tm, elapsed_tm, elapsed_tm2, elapsed_tm3;
 
-    if ((argc >= 3) && !strcmp(argv[1],"-p")) {percent = atoi(argv[2]); v = 3;}
-    if ((argc >= v) && !strcmp(argv[v],"-v")) {verbose=1; v++;}
+    if ((argc >= 3) && (strcmp(argv[1],"-p") == 0)) {percent = atoi(argv[2]); v = 3;}
+    if ((argc >= v) && (strcmp(argv[v],"-v") == 0)) {verbose=1; v++;}
     if (argc >= v) filename=argv[v];
     fd=open(filename,MODE);
 
@@ -102,7 +102,7 @@ int main(int argc, char *argv[]) {
         return -1;
     }
 
-    for(i=0; !done; i++) {
+    for(i=0; done==0; i++) {
 
           want = sizeof(int);
           dst = (char*)&keylen;
@@ -120,7 +120,8 @@ int main(int argc, char *argv[]) {
           if (done || err) break;
           if (keylen > max_keylen) max_keylen=keylen;
 
-          if ( (keyt = (stat_key*)malloc(sizeof(stat_key))) == NULL) {
+          keyt = (stat_key*)malloc(sizeof(stat_key));
+          if (keyt == NULL) {
               fprintf(stderr,"out of memory\n");
               exit(-1);
           }
@@ -129,7 +130,8 @@ int main(int argc, char *argv[]) {
 #ifdef UNALIGNED_KEYS
           padding = i%8;
 #endif
-          if ( (keyt->key = (char*)malloc(padding+keylen)) == NULL) {
+          keyt->key = (char*)malloc(padding+keylen);
+          if (keyt->key == NULL) {
               fprintf(stderr,"out of memory\n");
               exit(-1);
           }
@@ -149,7 +151,7 @@ int main(int argc, char *argv[]) {
                 err=1;
               } else if (rc >= 0) { want -= rc; dst += rc; goto readmore2; }
           }
-          if (err) break;
+          if (err != 0) break;
           /* if percent was set to something less than 100%, skip some keys*/
           if (((rand()*1.0) / RAND_MAX) > ((percent*1.0)/100)) {
             free(keyt->key-padding);
@@ -159,7 +161,7 @@ int main(int argc, char *argv[]) {
 
           /* eliminate dups */
           HASH_FIND(hh,keys,keyt->key,keylen,keytmp);
-          if (keytmp) {
+          if (keytmp != NULL) {
               dups++;
               free(keyt->key - padding);
             free(keyt);
@@ -168,7 +170,7 @@ int main(int argc, char *argv[]) {
           }
     }
 
-    if (verbose) {
+    if (verbose != 0) {
       unsigned key_count = HASH_COUNT(keys);
       fprintf(stderr,"max key length: %u\n", max_keylen);
       fprintf(stderr,"number unique keys: %u\n", key_count);
@@ -189,27 +191,27 @@ int main(int argc, char *argv[]) {
     gettimeofday(&start_tm,NULL);
     for(keyt = keys; keyt != NULL; keyt=(stat_key*)keyt->hh.next) {
         HASH_FIND(hh2,keys2,keyt->key,keyt->len,keytmp);
-        if (!keytmp) fprintf(stderr,"internal error, key not found\n");
+        if (keytmp == NULL) fprintf(stderr,"internal error, key not found\n");
     }
     gettimeofday(&end_tm,NULL);
     timersub(&end_tm, &start_tm, &elapsed_tm2);
 
     /* now delete all items in the new hash, measuring elapsed time */
     gettimeofday(&start_tm,NULL);
-    while (keys2) {
+    while (keys2 != NULL) {
         keytmp = keys2;
         HASH_DELETE(hh2,keys2,keytmp);
     }
     gettimeofday(&end_tm,NULL);
     timersub(&end_tm, &start_tm, &elapsed_tm3);
 
-    if (!err) {
-        printf("%.3f,%d,%d,%d,%s,%ld,%ld,%ld\n",
+    if (err == 0) {
+        printf("%.3f,%u,%u,%d,%s,%ld,%ld,%ld\n",
         1-(1.0*keys->hh.tbl->nonideal_items/keys->hh.tbl->num_items),
         keys->hh.tbl->num_items,
         keys->hh.tbl->num_buckets,
         dups,
-        (keys->hh.tbl->noexpand ? "nx" : "ok"),
+        (keys->hh.tbl->noexpand != 0U) ? "nx" : "ok",
         (elapsed_tm.tv_sec * 1000000) + elapsed_tm.tv_usec,
         (elapsed_tm2.tv_sec * 1000000) + elapsed_tm2.tv_usec,
         (elapsed_tm3.tv_sec * 1000000) + elapsed_tm3.tv_usec );

+ 1 - 1
tests/test40.c

@@ -23,7 +23,7 @@ int main(int argc, char *argv[]) {
     }
 
     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 - 4
tests/test41.c

@@ -10,7 +10,7 @@ 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;
+    for(i=0;i<10;i++) els[i].id=(int)'a'+i;
 
     /* test CDL macros */
     printf("CDL macros\n");
@@ -25,7 +25,7 @@ int main(int argc, char *argv[]) {
         CDL_DELETE(head,e);
     }
     printf("\n");
-    if (head) printf("non-null head\n");
+    if (head != NULL) printf("non-null head\n");
 
     /* test DL macros */
     printf("DL macros\n");
@@ -38,7 +38,7 @@ int main(int argc, char *argv[]) {
         DL_DELETE(head,e);
     }
     printf("\n");
-    if (head) printf("non-null head\n");
+    if (head != NULL) printf("non-null head\n");
 
     /* test LL macros */
     printf("LL macros\n");
@@ -51,7 +51,7 @@ int main(int argc, char *argv[]) {
         LL_DELETE(head,e);
     }
     printf("\n");
-    if (head) printf("non-null head\n");
+    if (head != NULL) printf("non-null head\n");
 
     return 0;
 }

+ 7 - 7
tests/test42.c

@@ -12,7 +12,7 @@ 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;
+    for(i=0;i<10;i++) els[i].id=(int)'a'+i;
 
     /* test LL macros */
     printf("LL macros\n");
@@ -23,9 +23,9 @@ int main(int argc, char *argv[]) {
         printf("%c ", e->id);
     printf("\n");
     LL_SEARCH_SCALAR(head, e, id, 'b');
-    if (e) printf("search scalar found b\n");
+    if (e != NULL) printf("search scalar found b\n");
     LL_SEARCH(head, e, &els[0], eltcmp);
-    if (e) printf("search found %c\n",e->id);
+    if (e != NULL) printf("search found %c\n",e->id);
     LL_FOREACH_SAFE(head,e,tmp) LL_DELETE(head,e);
 
     printf("\n");
@@ -39,9 +39,9 @@ int main(int argc, char *argv[]) {
         printf("%c ", e->id);
     printf("\n");
     DL_SEARCH_SCALAR(head, e, id, 'b');
-    if (e) printf("search scalar found b\n");
+    if (e != NULL) printf("search scalar found b\n");
     DL_SEARCH(head, e, &els[0], eltcmp);
-    if (e) printf("search found %c\n",e->id);
+    if (e != NULL) printf("search found %c\n",e->id);
     DL_FOREACH_SAFE(head,e,tmp) DL_DELETE(head,e);
     printf("\n");
 
@@ -54,9 +54,9 @@ int main(int argc, char *argv[]) {
         printf("%c ", e->id);
     printf("\n");
     CDL_SEARCH_SCALAR(head, e, id, 'b');
-    if (e) printf("search scalar found b\n");
+    if (e != NULL) printf("search scalar found b\n");
     CDL_SEARCH(head, e, &els[0], eltcmp);
-    if (e) printf("search found %c\n",e->id);
+    if (e != NULL) printf("search found %c\n",e->id);
     CDL_FOREACH_SAFE(head,e,tmp,tmp2) CDL_DELETE(head,e);
 
 

+ 28 - 29
tests/test43.c

@@ -6,71 +6,70 @@ typedef struct {
     int b;
 } intpair_t;
 
-UT_icd pairicd = { sizeof(intpair_t),NULL,NULL,NULL};
-
 int main() {
   UT_array *pairs, *pairs_cpy;
   intpair_t it, *ip;
+  UT_icd pairicd = { sizeof(intpair_t),NULL,NULL,NULL};
   size_t zero=0;
   utarray_new(pairs, &pairicd);
-  printf("length is %d\n", utarray_len(pairs));
+  printf("length is %u\n", utarray_len(pairs));
   it.a = 1; it.b=2; utarray_push_back(pairs, &it); printf("push\n");
-  printf("length is %d\n", utarray_len(pairs));
+  printf("length is %u\n", utarray_len(pairs));
   ip = (intpair_t*)utarray_back(pairs);
   printf("back is %d %d\n", ip->a, ip->b);
   utarray_pop_back(pairs); printf("pop\n");
-  printf("length is %d\n", utarray_len(pairs));
+  printf("length is %u\n", utarray_len(pairs));
   it.a = 1; it.b=2; utarray_push_back(pairs, &it); printf("push\n");
   it.a = 3; it.b=4; utarray_push_back(pairs, &it); printf("push\n");
-  printf("length is %d\n", utarray_len(pairs));
+  printf("length is %u\n", utarray_len(pairs));
   ip=NULL;
-  while( (ip=(intpair_t*)utarray_next(pairs,ip))) printf("%d %d\n", ip->a, ip->b);
+  while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) printf("%d %d\n", ip->a, ip->b);
   utarray_erase(pairs,0,1); printf("erase [0]\n");
-  printf("length is %d\n", utarray_len(pairs));
-  while( (ip=(intpair_t*)utarray_next(pairs,ip))) printf("%d %d\n", ip->a, ip->b);
+  printf("length is %u\n", utarray_len(pairs));
+  while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) printf("%d %d\n", ip->a, ip->b);
   it.a = 1; it.b=2; utarray_push_back(pairs, &it); printf("push\n");
-  while( (ip=(intpair_t*)utarray_next(pairs,ip))) printf("%d %d\n", ip->a, ip->b);
+  while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) printf("%d %d\n", ip->a, ip->b);
   utarray_clear(pairs); printf("clear\n");
-  printf("length is %d\n", utarray_len(pairs));
+  printf("length is %u\n", utarray_len(pairs));
   utarray_extend_back(pairs); printf("extend\n");
   ip = (intpair_t*)utarray_back(pairs);
-  printf("length is %d\n", utarray_len(pairs));
+  printf("length is %u\n", utarray_len(pairs));
   printf("ip points to [0] ? %s\n", (ip==(intpair_t*)utarray_front(pairs)) ? "yes" : "no");
   it.a = 1; it.b=2; utarray_push_back(pairs, &it); printf("push\n");
   ip=NULL;
-  while( (ip=(intpair_t*)utarray_next(pairs,ip))) printf("%d %d\n", ip->a, ip->b);
+  while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) printf("%d %d\n", ip->a, ip->b);
   utarray_erase(pairs,1,1); printf("erase [1]\n");
-  printf("length is %d\n", utarray_len(pairs));
-  while( (ip=(intpair_t*)utarray_next(pairs,ip))) printf("%d %d\n", ip->a, ip->b);
+  printf("length is %u\n", utarray_len(pairs));
+  while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) printf("%d %d\n", ip->a, ip->b);
   it.a = 3; it.b=4; utarray_push_back(pairs, &it); printf("push\n");
-  for(ip=(intpair_t*)utarray_front(pairs);ip;ip=(intpair_t*)utarray_next(pairs,ip)) {
+  for(ip=(intpair_t*)utarray_front(pairs);ip!=NULL;ip=(intpair_t*)utarray_next(pairs,ip)) {
     printf("%d %d\n", ip->a,ip->b);
   }
   ip = (intpair_t*)utarray_back(pairs);
   printf("back is %d %d\n", ip->a, ip->b);
   utarray_new(pairs_cpy, &pairicd);
   utarray_concat(pairs_cpy, pairs);  printf("copy\n");
-  printf("cpy length is %d\n", utarray_len(pairs_cpy));
+  printf("cpy length is %u\n", utarray_len(pairs_cpy));
   ip=NULL;
-  while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip))) printf("cpy %d %d\n", ip->a, ip->b);
+  while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip)) != NULL ) printf("cpy %d %d\n", ip->a, ip->b);
   it.a=5; it.b=6; utarray_insert(pairs_cpy, &it, 0); printf("insert cpy[0]\n");
-  printf("cpy length is %d\n", utarray_len(pairs_cpy));
-  while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip))) printf("cpy %d %d\n", ip->a, ip->b);
+  printf("cpy length is %u\n", utarray_len(pairs_cpy));
+  while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip)) != NULL ) printf("cpy %d %d\n", ip->a, ip->b);
   utarray_erase(pairs_cpy,0,2); printf("erase cpy [0] [1]\n");
-  printf("cpy length is %d\n", utarray_len(pairs_cpy));
-  while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip))) printf("cpy %d %d\n", ip->a, ip->b);
+  printf("cpy length is %u\n", utarray_len(pairs_cpy));
+  while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip)) != NULL ) printf("cpy %d %d\n", ip->a, ip->b);
   utarray_inserta(pairs_cpy, pairs, 1); printf("inserta at cpy[1]\n");
-  printf("cpy length is %d\n", utarray_len(pairs_cpy));
-  while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip))) printf("cpy %d %d\n", ip->a, ip->b);
+  printf("cpy length is %u\n", utarray_len(pairs_cpy));
+  while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip)) != NULL ) printf("cpy %d %d\n", ip->a, ip->b);
   utarray_free(pairs_cpy); printf("free cpy\n");
-  printf("length is %d\n", utarray_len(pairs));
+  printf("length is %u\n", utarray_len(pairs));
   utarray_resize(pairs, 30); printf("resize to 30\n");
-  printf("length is %d\n", utarray_len(pairs));
-  while( (ip=(intpair_t*)utarray_next(pairs,ip))) printf("%d %d\n", ip->a, ip->b);
+  printf("length is %u\n", utarray_len(pairs));
+  while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) printf("%d %d\n", ip->a, ip->b);
   utarray_resize(pairs, 1); printf("resize to 1\n");
-  printf("length is %d\n", utarray_len(pairs));
+  printf("length is %u\n", utarray_len(pairs));
   utarray_resize(pairs, zero); printf("resize to 0\n");
-  printf("length is %d\n", utarray_len(pairs));
+  printf("length is %u\n", utarray_len(pairs));
   utarray_free(pairs); printf("free\n");
   return 0;
 }

+ 9 - 9
tests/test44.c

@@ -12,31 +12,31 @@ int main() {
   int i, *p;
   utarray_new(a, &ut_int_icd);
   for(i=0;i<10;i++) utarray_push_back(a,&i);
-  for(p=(int*)utarray_front(a); p; p=(int*)utarray_next(a,p)) printf("%d ",*p);
+  for(p=(int*)utarray_front(a); p!=NULL; p=(int*)utarray_next(a,p)) printf("%d ",*p);
   printf("\n");
   utarray_sort(a,reverse);
-  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
+  while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ", *p);
   printf("\n");
   utarray_erase(a,3,3);
-  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
+  while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ", *p);
   printf("\n");
   utarray_erase(a,1,2);
-  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
+  while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ", *p);
   printf("\n");
   utarray_erase(a,0,1);
-  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
+  while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ", *p);
   printf("\n");
   utarray_erase(a,3,1);
-  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
+  while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ", *p);
   printf("\n");
   utarray_resize(a,5);
-  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
+  while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ", *p);
   printf("\n");
   utarray_resize(a,3);
-  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
+  while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ", *p);
   printf("\n");
   utarray_erase(a,0,3);
-  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
+  while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ", *p);
   printf("\n");
   utarray_free(a);
   return 0;

+ 3 - 3
tests/test45.c

@@ -8,15 +8,15 @@ int main() {
   for(i=0;i<10;i++) utarray_push_back(a,&i);
   utarray_pop_back(a);
   utarray_erase(a,0,1);
-  while ( (p=(int*)utarray_next(a,p))) printf("%d ",*p); printf("\n");
+  while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ",*p); printf("\n");
   i = 100;
   utarray_insert(a,&i,3);
-  while ( (p=(int*)utarray_next(a,p))) printf("%d ",*p); printf("\n");
+  while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ",*p); printf("\n");
   utarray_extend_back(a);
   p = (int*)utarray_back(a);
   *p = 1000;
   p = NULL;
-  while ( (p=(int*)utarray_next(a,p))) printf("%d ",*p); printf("\n");
+  while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ",*p); printf("\n");
   utarray_clear(a);
   utarray_free(a);
   return 0;

+ 9 - 9
tests/test46.c

@@ -19,29 +19,29 @@ int main() {
   utarray_new(strs, &ut_str_icd);
   s="hello"; utarray_push_back(strs, &s);
   s="world"; utarray_push_back(strs, &s);
-  while ( (p=(char**)utarray_next(strs,p))) printf("%s ",*p); printf("\n");
+  while ( (p=(char**)utarray_next(strs,p)) != NULL ) printf("%s ",*p); printf("\n");
   s="begin"; utarray_insert(strs,&s,0);
-  while ( (p=(char**)utarray_next(strs,p))) printf("%s ",*p); printf("\n");
+  while ( (p=(char**)utarray_next(strs,p)) != NULL ) printf("%s ",*p); printf("\n");
   utarray_new(strs2, &ut_str_icd);
   s="alt"; utarray_push_back(strs2, &s);
   s="oth"; utarray_push_back(strs2, &s);
   utarray_inserta(strs2, strs, 1);
-  while ( (p=(char**)utarray_next(strs2,p))) printf("%s ",*p); printf("\n");
+  while ( (p=(char**)utarray_next(strs2,p)) != NULL ) printf("%s ",*p); printf("\n");
   utarray_erase(strs2,0,2);
-  while ( (p=(char**)utarray_next(strs2,p))) printf("%s ",*p); printf("\n");
+  while ( (p=(char**)utarray_next(strs2,p)) != NULL ) printf("%s ",*p); printf("\n");
   utarray_pop_back(strs2);
-  while ( (p=(char**)utarray_next(strs2,p))) printf("%s ",*p); printf("\n");
+  while ( (p=(char**)utarray_next(strs2,p)) != NULL ) printf("%s ",*p); printf("\n");
   utarray_concat(strs2, strs);
-  while ( (p=(char**)utarray_next(strs2,p))) printf("%s ",*p); printf("\n");
+  while ( (p=(char**)utarray_next(strs2,p)) != NULL ) printf("%s ",*p); printf("\n");
   utarray_clear(strs2);
   utarray_concat(strs2, strs);
-  while ( (p=(char**)utarray_next(strs2,p))) printf("%s ",*p); printf("\n");
+  while ( (p=(char**)utarray_next(strs2,p)) != NULL ) printf("%s ",*p); printf("\n");
   printf("sorting strs2\n");
   utarray_sort(strs2,strsort);
-  while ( (p=(char**)utarray_next(strs2,p))) printf("%s ",*p); printf("\n");
+  while ( (p=(char**)utarray_next(strs2,p)) != NULL ) printf("%s ",*p); printf("\n");
   printf("reverse sorting strs2\n");
   utarray_sort(strs2,revsort);
-  while ( (p=(char**)utarray_next(strs2,p))) printf("%s ",*p); printf("\n");
+  while ( (p=(char**)utarray_next(strs2,p)) != NULL ) printf("%s ",*p); printf("\n");
   utarray_clear(strs2);
   utarray_free(strs2);
   utarray_free(strs);

+ 4 - 4
tests/test47.c

@@ -16,13 +16,13 @@ int main() {
     utstring_concat(s,t);
     printf("%s\n", utstring_body(s));
     utstring_clear(t);
-    printf("cleared, length t now: %d\n", utstring_len(t));
-    printf("length s now: %d\n", utstring_len(s));
+    printf("cleared, length t now: %u\n", utstring_len(t));
+    printf("length s now: %u\n", utstring_len(s));
     utstring_printf(t,"one %d two %u three %s", 1, 2, "(3)");
     printf("%s\n", utstring_body(t));
-    printf("length t now: %d\n", utstring_len(t));
-
+    printf("length t now: %u\n", utstring_len(t));
 
+    utstring_free(t);
     utstring_free(s);
     return 0;
 }

+ 1 - 1
tests/test49.c

@@ -10,7 +10,7 @@ int main() {
   s = "hello"; utarray_push_back(strs, &s);
   s = "world"; utarray_push_back(strs, &s);
   p = NULL;
-  while ( (p=(char**)utarray_next(strs,p))) {
+  while ( (p=(char**)utarray_next(strs,p)) != NULL ) {
     printf("%s\n",*p);
   }
 

+ 2 - 3
tests/test50.c

@@ -1,18 +1,17 @@
 #include <stdio.h>
 #include "utarray.h"
 
-UT_icd long_icd = {sizeof(long), NULL, NULL, NULL };
-
 int main() {
   UT_array *nums;
   long l, *p;
+  UT_icd long_icd = {sizeof(long), NULL, NULL, NULL };
   utarray_new(nums, &long_icd);
 
   l=1; utarray_push_back(nums, &l);
   l=2; utarray_push_back(nums, &l);
 
   p=NULL;
-  while( (p=(long*)utarray_next(nums,p))) printf("%ld\n", *p);
+  while( (p=(long*)utarray_next(nums,p)) != NULL ) printf("%ld\n", *p);
 
   utarray_free(nums);
   return 0;

+ 1 - 2
tests/test51.c

@@ -6,12 +6,11 @@ typedef struct {
     int b;
 } intpair_t;
 
-UT_icd intpair_icd = {sizeof(intpair_t), NULL, NULL, NULL};
-
 int main() {
 
   UT_array *pairs;
   intpair_t ip, *p;
+  UT_icd intpair_icd = {sizeof(intpair_t), NULL, NULL, NULL};
   utarray_new(pairs,&intpair_icd);
 
   ip.a=1;  ip.b=2;  utarray_push_back(pairs, &ip);

+ 5 - 6
tests/test52.c

@@ -10,27 +10,26 @@ typedef struct {
 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;
+  dst->s = (src->s != NULL) ? strdup(src->s) : NULL;
 }
 
 static void intchar_dtor(void *_elt) {
   intchar_t *elt = (intchar_t*)_elt;
-  if (elt->s) free(elt->s);
+  if (elt->s != NULL) free(elt->s);
 }
 
-UT_icd intchar_icd = {sizeof(intchar_t), NULL, intchar_copy, intchar_dtor};
-
 int main() {
   UT_array *intchars;
   intchar_t ic, *p;
+  UT_icd intchar_icd = {sizeof(intchar_t), NULL, intchar_copy, intchar_dtor};
   utarray_new(intchars, &intchar_icd);
 
   ic.a=1; ic.s="hello"; utarray_push_back(intchars, &ic);
   ic.a=2; ic.s="world"; utarray_push_back(intchars, &ic);
 
   p=NULL;
-  while( (p=(intchar_t*)utarray_next(intchars,p))) {
-    printf("%d %s\n", p->a, (p->s ? p->s : "null"));
+  while( (p=(intchar_t*)utarray_next(intchars,p)) != NULL ) {
+    printf("%d %s\n", p->a, (p->s != NULL) ? p->s : "null");
   }
 
   utarray_free(intchars);

+ 2 - 2
tests/test56.c

@@ -51,9 +51,9 @@ int main(int argc, char *argv[]) {
     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) {

+ 3 - 4
tests/test57.c

@@ -8,18 +8,17 @@ typedef struct {
   UT_hash_handle hh;
 } el_t;
 
-el_t *hash = NULL;
-char *someaddr = NULL;
-
 int main() {
   el_t *d;
+  el_t *hash = NULL;
+  char *someaddr = NULL;
   el_t *e = (el_t*)malloc(sizeof(el_t));
   if (!e) return -1;
   e->key = (void*)someaddr;
   e->i = 1;
   HASH_ADD_PTR(hash,key,e);
   HASH_FIND_PTR(hash, &someaddr, d);
-  if (d) printf("found\n");
+  if (d != NULL) printf("found\n");
 
   /* release memory */
   HASH_DEL(hash,e);

+ 5 - 4
tests/test58.c

@@ -9,7 +9,8 @@ typedef struct example_user_t {
 } example_user_t;
 
 int main(int argc,char *argv[]) {
-    int i,c;
+    int i;
+    unsigned c;
     example_user_t *user, *tmp, *users=NULL;
 
     /* create elements */
@@ -27,7 +28,7 @@ int main(int argc,char *argv[]) {
 
 
     c = HASH_COUNT(users);
-    printf("%d users. Deleting odd id's...\n", c);
+    printf("%u users. Deleting odd id's...\n", c);
     /* delete the odd id's */
     HASH_ITER(hh, users, user, tmp) {
         if (user->id & 1) HASH_DEL(users,user);
@@ -39,14 +40,14 @@ int main(int argc,char *argv[]) {
     }
 
     c = HASH_COUNT(users);
-    printf("%d users. Deleting remaining id's...\n", c);
+    printf("%u users. Deleting remaining id's...\n", c);
     /* delete all that are left */
     HASH_ITER(hh, users, user, tmp) {
         HASH_DEL(users,user);
     }
 
     c = HASH_COUNT(users);
-    printf("%d users.\n", c);
+    printf("%u users.\n", c);
     /* show the hash */
     for(user=users; user != NULL; user=(example_user_t*)(user->hh.next)) {
         printf("user %d, cookie %d\n", user->id, user->cookie);

+ 1 - 2
tests/test59.c

@@ -11,10 +11,9 @@ typedef struct item {
   UT_hash_handle hh;
 } item_t;
 
-item_t *items=NULL;
-
 int main(int argc, char *argvp[]) {
   item_t *item1, *item2, *tmp1, *tmp2;
+  item_t *items=NULL;
 
   /* make initial element */
   item_t *i = malloc(sizeof(*i));

+ 1 - 2
tests/test60.c

@@ -11,10 +11,9 @@ typedef struct item {
   UT_hash_handle hh;
 } item_t;
 
-item_t *items=NULL;
-
 int main(int argc, char *argvp[]) {
   item_t *item1, *item2, *tmp1, *tmp2;
+  item_t *items=NULL;
 
   /* make initial element */
   item_t *i = malloc(sizeof(*i));

+ 3 - 3
tests/test61.c

@@ -20,7 +20,7 @@ int main() {
   s = "three"; utarray_push_back(strs, &s);
 
   p = NULL;
-  while ( (p=(char**)utarray_next(strs,p))) {
+  while ( (p=(char**)utarray_next(strs,p)) != NULL ) {
     s = *p;
     printf("%s\n",s);
   }
@@ -29,11 +29,11 @@ int main() {
   utarray_sort(strs,strsort);
 
   p = NULL;
-  while ( (p=(char**)utarray_next(strs,p))) {
+  while ( (p=(char**)utarray_next(strs,p)) != NULL ) {
     s = *p;
     printf("finding %s\n",s);
     p = utarray_find(strs,&s,strsort);
-    printf(" %s\n", p ? (*p) : "failed");
+    printf(" %s\n", (p != NULL) ? (*p) : "failed");
   }
 
   utarray_free(strs);

+ 3 - 2
tests/test62.c

@@ -8,10 +8,10 @@
 #define MUR_PLUS2_ALIGNED(p) (((unsigned long)p & 0x3) == 2)
 #define MUR_PLUS3_ALIGNED(p) (((unsigned long)p & 0x3) == 3)
 
-#define yn(rc) (rc?"y":"n")
+#define yn(rc) ((rc!=0U)?"y":"n")
 int main(int argc,char*argv[]) {
   unsigned rc;
-  char *c = malloc(8);
+  char *c = malloc(8UL);
   *(c+0) = 0x00;  unsigned *al = (unsigned*)(c+0);
   *(c+1) = 0x01;  unsigned *u1 = (unsigned*)(c+1);
   *(c+2) = 0x02;  unsigned *u2 = (unsigned*)(c+2);
@@ -57,5 +57,6 @@ int main(int argc,char*argv[]) {
   rc = MUR_GETBLOCK(u3,0); printf("%x\n", rc);
 #endif
 
+  free(c);
   return 0;
 }

+ 3 - 3
tests/test63.c

@@ -6,12 +6,12 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-el *headA = NULL, *headB = 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 *headA = NULL;
+    el *headB = NULL;
+    for(i=0;i<10;i++) els[i].id=(int)'a'+i;
 
     /* test LL macros */
     printf("LL macros\n");

+ 3 - 3
tests/test64.c

@@ -6,12 +6,12 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-el *headA = NULL, *headB = 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 *headA = NULL;
+    el *headB = NULL;
+    for(i=0;i<10;i++) els[i].id=(int)'a'+i;
 
     /* test DL macros */
     printf("DL macros\n");

+ 3 - 2
tests/test65.c

@@ -7,7 +7,7 @@
 // by Jehiah Czebotar 2011 - [email protected]
 // this code is in the public domain http://unlicense.org/
 
-#define MAX_CACHE_SIZE 50  /* a real value would be much larger */
+#define MAX_CACHE_SIZE 50U  /* a real value would be much larger */
 
 struct CacheEntry {
     char *key;
@@ -20,7 +20,7 @@ static char * /*value*/ find_in_cache(char *key)
 {
     struct CacheEntry *entry;
     HASH_FIND_STR(cache, key, entry);
-    if (entry) {
+    if (entry != NULL) {
         // remove it (so the subsequent add will throw it on the front of the list)
         HASH_DELETE(hh, cache, entry);
         HASH_ADD_KEYPTR(hh, cache, entry->key, strlen(entry->key), entry);
@@ -33,6 +33,7 @@ static void add_to_cache(char *key, char *value)
 {
     struct CacheEntry *entry, *tmp_entry;
     entry = malloc(sizeof(struct CacheEntry));
+    if (entry == NULL) exit(-1);
     entry->key = strdup(key);
     entry->value = strdup(value);
     HASH_ADD_KEYPTR(hh, cache, entry->key, strlen(entry->key), entry);

+ 4 - 4
tests/test66.c

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

+ 1 - 1
tests/test67.c

@@ -16,7 +16,7 @@ int main() {
 
   /* the other form of iteration starting from NULL (back) */
   p=NULL;
-  while ( (p=(int*)utarray_prev(nums,p))) {
+  while ( (p=(int*)utarray_prev(nums,p)) != NULL ) {
     printf("%d\n",*p);
   }
 

+ 3 - 3
tests/test68.c

@@ -7,12 +7,12 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-el *headA, *headB = NULL;
-
 int main(int argc, char *argv[]) {
     int i;
     el els[20], *e, *tmp;
-    for(i=0;i<20;i++) els[i].id='a'+i;
+    el *headA = NULL;
+    el *headB = NULL;
+    for(i=0;i<20;i++) els[i].id=(int)'a'+i;
 
     /* test DL macros */
     printf("DL replace elem\n");

+ 3 - 3
tests/test69.c

@@ -7,12 +7,12 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-el *headA, *headB = NULL;
-
 int main(int argc, char *argv[]) {
     int i;
     el els[26], *e, *tmp;
-    for(i=0;i<25;i++) els[i].id='a'+i;
+    el *headA = NULL;
+    el *headB = NULL;
+    for(i=0;i<25;i++) els[i].id=(int)'a'+i;
 
     /* test DL macros */
     printf("DL prepend elem\n");

+ 3 - 3
tests/test70.c

@@ -7,12 +7,12 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-el *headA, *headB = NULL;
-
 int main(int argc, char *argv[]) {
     int i;
     el els[20], *e, *tmp;
-    for(i=0;i<20;i++) els[i].id='a'+i;
+    el *headA = NULL;
+    el *headB = NULL;
+    for(i=0;i<20;i++) els[i].id=(int)'a'+i;
 
     /* test LL macros */
     printf("LL replace elem\n");

+ 3 - 3
tests/test71.c

@@ -7,12 +7,12 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-el *headA, *headB = NULL;
-
 int main(int argc, char *argv[]) {
     int i;
     el els[26], *e, *tmp;
-    for(i=0;i<25;i++) els[i].id='a'+i;
+    el *headA = NULL;
+    el *headB = NULL;
+    for(i=0;i<25;i++) els[i].id=(int)'a'+i;
 
     /* test LL macros */
     printf("LL prepend elem\n");

+ 3 - 3
tests/test72.c

@@ -7,12 +7,12 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-el *headA, *headB = NULL;
-
 int main(int argc, char *argv[]) {
     int i;
     el els[20], *e, *tmp, *tmp2;
-    for(i=0;i<20;i++) els[i].id='a'+i;
+    el *headA = NULL;
+    el *headB = NULL;
+    for(i=0;i<20;i++) els[i].id=(int)'a'+i;
 
     /* test CDL macros */
     printf("CDL replace elem\n");

+ 3 - 3
tests/test73.c

@@ -7,12 +7,12 @@ typedef struct el {
     struct el *next, *prev;
 } el;
 
-el *headA, *headB = NULL;
-
 int main(int argc, char *argv[]) {
     int i;
     el els[26], *e, *tmp, *tmp2;
-    for(i=0;i<25;i++) els[i].id='a'+i;
+    el *headA = NULL;
+    el *headB = NULL;
+    for(i=0;i<25;i++) els[i].id=(int)'a'+i;
 
     /* test CDL macros */
     printf("CDL prepend elem\n");

+ 2 - 3
tests/test78.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 - 2
tests/test80.c

@@ -6,12 +6,12 @@ int main() {
   int i, *p;
   utarray_new(a, &ut_int_icd);
   for(i=0;i<10;i++) utarray_push_back(a,&i);
-  for(p=(int*)utarray_front(a); p; p=(int*)utarray_next(a,p)) printf("%d ",*p);
+  for(p=(int*)utarray_front(a); p!=NULL; p=(int*)utarray_next(a,p)) printf("%d ",*p);
   printf("\n");
   printf("len: %u\n\n", utarray_len(a));
 
   i=11; utarray_insert(a, &i, 11);
-  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p); printf("\n");
+  while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ", *p); printf("\n");
   printf("len: %u\n\n", utarray_len(a));
 
   utarray_free(a);

+ 2 - 2
tests/test81.c

@@ -6,12 +6,12 @@ int main() {
   int i, *p;
   utarray_new(a, &ut_int_icd);
   for(i=0;i<10;i++) utarray_push_back(a,&i);
-  for(p=(int*)utarray_front(a); p; p=(int*)utarray_next(a,p)) printf("%d ",*p);
+  for(p=(int*)utarray_front(a); p!=NULL; p=(int*)utarray_next(a,p)) printf("%d ",*p);
   printf("\n");
   printf("len: %u\n\n", utarray_len(a));
 
   i=10; utarray_insert(a, &i, 10);
-  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p); printf("\n");
+  while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ", *p); printf("\n");
   printf("len: %u\n\n", utarray_len(a));
 
   utarray_free(a);

+ 4 - 4
tests/test82.c

@@ -8,20 +8,20 @@ int main() {
   utarray_new(b, &ut_int_icd);
 
   for(i=0;i<10;i++) utarray_push_back(a,&i);
-  for(p=(int*)utarray_front(a); p; p=(int*)utarray_next(a,p)) printf("%d ",*p);
+  for(p=(int*)utarray_front(a); p!=NULL; p=(int*)utarray_next(a,p)) printf("%d ",*p);
   printf("\n");
   printf("len: %u\n\n", utarray_len(a));
 
   utarray_inserta(b,a,10);
-  for(p=(int*)utarray_front(b); p; p=(int*)utarray_next(b,p)) printf("%d ",*p);
+  for(p=(int*)utarray_front(b); p!=NULL; p=(int*)utarray_next(b,p)) printf("%d ",*p);
   printf("len: %u\n\n", utarray_len(b));
 
   utarray_inserta(b,a,0);
-  for(p=(int*)utarray_front(b); p; p=(int*)utarray_next(b,p)) printf("%d ",*p);
+  for(p=(int*)utarray_front(b); p!=NULL; p=(int*)utarray_next(b,p)) printf("%d ",*p);
   printf("len: %u\n\n", utarray_len(b));
 
   utarray_inserta(b,a,25);
-  for(p=(int*)utarray_front(b); p; p=(int*)utarray_next(b,p)) printf("%d ",*p);
+  for(p=(int*)utarray_front(b); p!=NULL; p=(int*)utarray_next(b,p)) printf("%d ",*p);
   printf("len: %u\n\n", utarray_len(b));
 
   utarray_free(a);

+ 7 - 6
tests/test83.c

@@ -15,10 +15,10 @@ int main(int argc, char*argv[]) {
                       "gil", "buck", "ted", NULL };
     int id=0;
 
-    for(name=names; *name; name++) {
+    for(name=names; *name!=NULL; name++) {
         person = (person_t*)malloc(sizeof(person_t));
         if (person == NULL) exit(-1);
-        strncpy(person->first_name, *name,10);
+        strncpy(person->first_name, *name,sizeof(person->first_name));
         person->id = id++;
         HASH_ADD_STR(people,first_name,person);
         printf("added %s (id %d)\n", person->first_name, person->id);
@@ -27,16 +27,17 @@ int main(int argc, char*argv[]) {
     person=NULL;
     person_t **p=&person;
 
-    for(name=names; *name; name++) {
+    for(name=names; *name!=NULL; name++) {
         HASH_FIND_STR(people,*name,*p);
-        if (person) {
+        if (person != NULL) {
             printf("found %s (id %d)\n", person->first_name, person->id);
             new_person  = malloc(sizeof(person_t));
+            if (new_person == NULL) exit(-1);
             memcpy(new_person, person, sizeof(person_t));
             new_person->id = person->id*10;
             HASH_REPLACE_STR(people,first_name,new_person,tmp);
-            printf("replaced (%c) with %s (id %d)\n", tmp?'y':'n', new_person->first_name, new_person->id);
-            if (tmp) free(tmp);
+            printf("replaced (%c) with %s (id %d)\n", (tmp!=NULL)?'y':'n', new_person->first_name, new_person->id);
+            if (tmp != NULL) free(tmp);
         } else {
             printf("failed to find %s\n", *name);
         }

+ 9 - 9
tests/test84.c

@@ -15,11 +15,11 @@ int main(int argc, char*argv[]) {
                       "gil", "buck", "ted", NULL };
     int id=0;
 
-    for(name=names; *name; name++) {
+    for(name=names; *name!=NULL; name++) {
         person = (person_t*)malloc(sizeof(person_t));
         if (person == NULL) exit(-1);
-        person->first_name = malloc(10);
-        strncpy(person->first_name, *name,10);
+        person->first_name = malloc(10UL);
+        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);
@@ -28,17 +28,17 @@ int main(int argc, char*argv[]) {
     person=NULL;
     person_t **p=&person;
 
-    for(name=names; *name; name++) {
+    for(name=names; *name!=NULL; name++) {
         HASH_FIND_STR(people,*name,*p);
-        if (person) {
+        if (person != NULL) {
             printf("found %s (id %d)\n", person->first_name, person->id);
             new_person  = malloc(sizeof(person_t));
-            new_person->first_name = malloc(10);
-            strncpy(new_person->first_name, person->first_name,10);
+            new_person->first_name = malloc(10UL);
+            strncpy(new_person->first_name, person->first_name,10UL);
             new_person->id = person->id*10;
             HASH_REPLACE_STR(people,first_name,new_person,tmp);
-            printf("replaced (%c) with %s (id %d)\n", tmp?'y':'n', new_person->first_name, new_person->id);
-            if (tmp) {free(tmp->first_name); free(tmp);}
+            printf("replaced (%c) with %s (id %d)\n", (tmp!=NULL)?'y':'n', new_person->first_name, new_person->id);
+            if (tmp != NULL) {free(tmp->first_name); free(tmp);}
         } else {
             printf("failed to find %s\n", *name);
         }

+ 2 - 2
tests/test85.c

@@ -22,11 +22,11 @@ int main(int argc,char *argv[]) {
     }
 
    size_t s = HASH_OVERHEAD(hh,users);
-   printf("overhead %s\n", (s==0)?"zero":"non-zero");
+   printf("overhead %s\n", (s==0U)?"zero":"non-zero");
    HASH_CLEAR(hh,users);  
    // should free those elements 
    // but this test is not concerned with that
    s = HASH_OVERHEAD(hh,users);
-   printf("overhead %s\n", (s==0)?"zero":"non-zero");
+   printf("overhead %s\n", (s==0U)?"zero":"non-zero");
    return 0;
 }