]> granicus.if.org Git - gc/commitdiff
Eliminate CSA warning of staticroot that can be a local variable (tests)
authorIvan Maidanski <ivmai@mail.ru>
Fri, 21 Jul 2017 08:01:01 +0000 (11:01 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 21 Jul 2017 08:01:01 +0000 (11:01 +0300)
* tests/staticrootstest.c (staticroot): Remove redundant initialization
to zero; add comment.
* tests/staticrootstest.c (init_staticroot): New function; move
staticroot=libsrl_init() from main(); add comment.
* tests/staticrootstest.c (main): Call init_staticroot().

tests/staticrootstest.c

index 34ce9b40be76a333d1fa05696199d920bc6aef43..fc2b9b36ad0c9146f11aff738ccf2048ee91649c 100644 (file)
@@ -25,7 +25,7 @@ struct treenode *root[10] = { NULL };
 /* be placed to .data section instead of .bss).                         */
 struct treenode *root_nz[10] = { (void *)(GC_word)1 };
 
-static char *staticroot = 0;
+static char *staticroot; /* intentionally static */
 
 GC_TEST_IMPORT_API struct treenode * libsrl_mktree(int i);
 GC_TEST_IMPORT_API void * libsrl_init(void);
@@ -33,6 +33,14 @@ GC_TEST_IMPORT_API struct treenode ** libsrl_getpelem(int i, int j);
 
 GC_TEST_IMPORT_API struct treenode ** libsrl_getpelem2(int i, int j);
 
+void init_staticroot(void)
+{
+  /* Intentionally put staticroot initialization in a function other    */
+  /* than main to prevent CSA warning that staticroot variable can be   */
+  /* changed to be a local one).                                        */
+  staticroot = libsrl_init();
+}
+
 int main(void)
 {
   int i, j;
@@ -40,7 +48,7 @@ int main(void)
 # ifdef STATICROOTSLIB_INIT_IN_MAIN
     GC_INIT();
 # endif
-  staticroot = libsrl_init();
+  init_staticroot();
   if (NULL == staticroot) {
     fprintf(stderr, "GC_malloc returned NULL\n");
     return 2;