Browse Source

Merge pull request #55 from fperrad/lint_tests_20150417

Lint tests 20150417
Troy D. Hanson 10 years ago
parent
commit
0107a918b0
12 changed files with 20 additions and 3 deletions
  1. 2 0
      tests/hashscan.c
  2. 1 0
      tests/test36.c
  3. 1 0
      tests/test37.c
  4. 1 0
      tests/test39.c
  5. 1 0
      tests/test40.c
  6. 1 1
      tests/test58.c
  7. 2 0
      tests/test59.c
  8. 2 0
      tests/test60.c
  9. 1 0
      tests/test62.c
  10. 2 2
      tests/test65.c
  11. 3 0
      tests/test79.c
  12. 3 0
      tests/test84.c

+ 2 - 0
tests/hashscan.c

@@ -466,6 +466,7 @@ static int scan(pid_t pid) {
     vma.start = (void *)vm_entry.pve_start;
     vma.end = (void *)vm_entry.pve_end;
     vmas = (vma_t *) realloc(vmas, (num_vmas + 1) * sizeof(vma_t));
+    if (vmas == NULL) exit(-1);
     vmas[num_vmas++] = vma;
   }
 
@@ -523,6 +524,7 @@ static int scan(pid_t pid) {
       if (vma.perms[0] != 'r') continue;          /* only readable vma's */
       if (memcmp(vma.device,"fd",2)==0) continue; /* skip mapped files */
       vmas = (vma_t*)realloc(vmas, (num_vmas+1) * sizeof(vma_t));
+      if (vmas == NULL) exit(-1);
       vmas[num_vmas++] = vma;
     }
   }

+ 1 - 0
tests/test36.c

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

+ 1 - 0
tests/test37.c

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

+ 1 - 0
tests/test39.c

@@ -16,6 +16,7 @@ int main() {
   for(i=0; i < sizeof(keys)/sizeof(keys[0]); i++) {
     printf("adding key %s\n", keys[i]);
     nsp = (ns_t*)malloc(sizeof(ns_t));
+    if (nsp == NULL) exit(-1);
     nsp->name = keys[i];
     HASH_ADD_KEYPTR(hh,head,nsp->name,strlen(nsp->name),nsp);
   }

+ 1 - 0
tests/test40.c

@@ -17,6 +17,7 @@ int main(int argc, char *argv[]) {
 
     for (n = names; *n != NULL; n++) {
         s = (struct my_struct*)malloc(sizeof(struct my_struct));
+        if (s == NULL) exit(-1);
         s->name = *n;
         s->id = i++;
         HASH_ADD_KEYPTR( hh, users, s->name, strlen(s->name), s );

+ 1 - 1
tests/test58.c

@@ -31,7 +31,7 @@ int main(int argc,char *argv[]) {
     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);
+        if ((user->id & 1) != 0) HASH_DEL(users,user);
     }
 
     /* show the hash */

+ 2 - 0
tests/test59.c

@@ -17,6 +17,7 @@ int main(int argc, char *argvp[]) {
 
   /* make initial element */
   item_t *i = malloc(sizeof(*i));
+  if (i == NULL) exit(-1);
   strcpy(i->name, "bob");
   i->sub = NULL;
   i->val = 0;
@@ -24,6 +25,7 @@ int main(int argc, char *argvp[]) {
 
   /* add a sub hash table off this element */
   item_t *s = malloc(sizeof(*s));
+  if (s == NULL) exit(-1);
   strcpy(s->name, "age");
   s->sub = NULL;
   s->val = 37;

+ 2 - 0
tests/test60.c

@@ -17,6 +17,7 @@ int main(int argc, char *argvp[]) {
 
   /* make initial element */
   item_t *i = malloc(sizeof(*i));
+  if (i == NULL) exit(-1);
   strcpy(i->name, "bob");
   i->sub = NULL;
   i->val = 0;
@@ -24,6 +25,7 @@ int main(int argc, char *argvp[]) {
 
   /* add a sub hash table off this element */
   item_t *s = malloc(sizeof(*s));
+  if (s == NULL) exit(-1);
   strcpy(s->name, "age");
   s->sub = NULL;
   s->val = 37;

+ 1 - 0
tests/test62.c

@@ -12,6 +12,7 @@
 int main(int argc,char*argv[]) {
   unsigned rc;
   char *c = malloc(8UL);
+  if (c == NULL) exit(-1);
   *(c+0) = 0x00;  unsigned *al = (unsigned*)(c+0);
   *(c+1) = 0x01;  unsigned *u1 = (unsigned*)(c+1);
   *(c+2) = 0x02;  unsigned *u2 = (unsigned*)(c+2);

+ 2 - 2
tests/test65.c

@@ -16,7 +16,7 @@ struct CacheEntry {
 };
 struct CacheEntry *cache = NULL;
 
-static char * /*value*/ find_in_cache(char *key)
+static char * /*value*/ find_in_cache(const char *key)
 {
     struct CacheEntry *entry;
     HASH_FIND_STR(cache, key, entry);
@@ -29,7 +29,7 @@ static char * /*value*/ find_in_cache(char *key)
     return NULL;
 }
 
-static void add_to_cache(char *key, char *value)
+static void add_to_cache(const char *key, const char *value)
 {
     struct CacheEntry *entry, *tmp_entry;
     entry = malloc(sizeof(struct CacheEntry));

+ 3 - 0
tests/test79.c

@@ -21,6 +21,7 @@ int main(int argc, char *argv[]) {
   hs_t *hs_head=NULL, *tmp, *replaced=NULL;
 
   tmp = (hs_t*)malloc(sizeof(hs_t));
+  if (tmp == NULL) exit(-1);
   tmp->id = 10;
   tmp->tag = 100;
   HASH_REPLACE_INT(hs_head,id,tmp,replaced);
@@ -32,6 +33,7 @@ int main(int argc, char *argv[]) {
   pr(&hs_head);
 
   tmp = (hs_t*)malloc(sizeof(hs_t));
+  if (tmp == NULL) exit(-1);
   tmp->id=11;
   tmp->tag = 101;
   HASH_REPLACE_INT(hs_head,id,tmp,replaced);
@@ -43,6 +45,7 @@ int main(int argc, char *argv[]) {
   pr(&hs_head);
 
   tmp = (hs_t*)malloc(sizeof(hs_t));
+  if (tmp == NULL) exit(-1);
   tmp->id=11;
   tmp->tag = 102;
   HASH_REPLACE_INT(hs_head,id,tmp,replaced);

+ 3 - 0
tests/test84.c

@@ -19,6 +19,7 @@ int main(int argc, char*argv[]) {
         person = (person_t*)malloc(sizeof(person_t));
         if (person == NULL) exit(-1);
         person->first_name = malloc(10UL);
+        if (person->first_name == NULL) exit(-1);
         strncpy(person->first_name, *name,10UL);
         person->id = id++;
         HASH_ADD_STR(people,first_name,person);
@@ -33,7 +34,9 @@ int main(int argc, char*argv[]) {
         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);
             new_person->first_name = malloc(10UL);
+            if (new_person->first_name == NULL) exit(-1);
             strncpy(new_person->first_name, person->first_name,10UL);
             new_person->id = person->id*10;
             HASH_REPLACE_STR(people,first_name,new_person,tmp);