This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix may be uninitialized warnings in libgfortran


We get a number of these warnings in libgfortran:

/cvs/gcc/libgfortran/generated/eoshift1_4.c:73: warning: ‘len’ may be used uninitialized in this function

All of them look like false positives but the algorithm is written in
a way that the compiler cannot catch it.  I propose to initialize the
warnings - this is AFAIK the same way we do in the rest of the
compiler.

Ok to commit the appended patch?

Tested on Linux/x86-64.

Andreas

	* m4/eoshift1.m4: Initialize variables to avoid warnings.
	* m4/eoshift3.m4: Initialize variables to avoid warnings.
	* generated/eoshift1_4.c, generated/eoshift1_8.c,
	generated/eoshift3_4.c, generated/eoshift3_8.c: Regenerated.

	* intrinsics/spread_generic.c (spread): Initialize variables to
	avoid warnings.

	* intrinsics/eoshift0.c (eoshift0): Initialize variables to avoid
	warnings.

	* io/list_read.c (nml_get_obj_data): Initialize variables to avoid
	warnings.

Attachment: pgp00000.pgp
Description: PGP signature

============================================================
Index: libgfortran/generated/eoshift1_4.c
--- generated/eoshift1_4.c	4 May 2005 21:38:15 -0000	1.6
+++ generated/eoshift1_4.c	15 May 2005 12:38:45 -0000
@@ -1,5 +1,5 @@
 /* Implementation of the EOSHIFT intrinsic
-   Copyright 2002 Free Software Foundation, Inc.
+   Copyright 2002, 2005 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
@@ -76,6 +76,12 @@ eoshift1_4 (const gfc_array_char *ret,
   GFC_INTEGER_4 sh;
   GFC_INTEGER_4 delta;
 
+  /* The compiler cannot figure out that these are set, initialize
+     them to avoid warnings.  */
+  len = 0;
+  soffset = 0;
+  roffset = 0;
+
   if (pwhich)
     which = *pwhich - 1;
   else
============================================================
Index: libgfortran/generated/eoshift1_8.c
--- generated/eoshift1_8.c	4 May 2005 21:38:15 -0000	1.6
+++ generated/eoshift1_8.c	15 May 2005 12:38:45 -0000
@@ -1,5 +1,5 @@
 /* Implementation of the EOSHIFT intrinsic
-   Copyright 2002 Free Software Foundation, Inc.
+   Copyright 2002, 2005 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
@@ -76,6 +76,12 @@ eoshift1_8 (const gfc_array_char *ret,
   GFC_INTEGER_8 sh;
   GFC_INTEGER_8 delta;
 
+  /* The compiler cannot figure out that these are set, initialize
+     them to avoid warnings.  */
+  len = 0;
+  soffset = 0;
+  roffset = 0;
+
   if (pwhich)
     which = *pwhich - 1;
   else
============================================================
Index: libgfortran/generated/eoshift3_4.c
--- generated/eoshift3_4.c	4 May 2005 21:38:16 -0000	1.6
+++ generated/eoshift3_4.c	15 May 2005 12:38:45 -0000
@@ -1,5 +1,5 @@
 /* Implementation of the EOSHIFT intrinsic
-   Copyright 2002 Free Software Foundation, Inc.
+   Copyright 2002, 2005 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
@@ -78,6 +78,12 @@ eoshift3_4 (gfc_array_char *ret, gfc_arr
   GFC_INTEGER_4 sh;
   GFC_INTEGER_4 delta;
 
+  /* The compiler cannot figure out that these are set, initialize
+     them to avoid warnings.  */
+  len = 0;
+  soffset = 0;
+  roffset = 0;
+
   if (pwhich)
     which = *pwhich - 1;
   else
============================================================
Index: libgfortran/generated/eoshift3_8.c
--- generated/eoshift3_8.c	4 May 2005 21:38:16 -0000	1.6
+++ generated/eoshift3_8.c	15 May 2005 12:38:45 -0000
@@ -1,5 +1,5 @@
 /* Implementation of the EOSHIFT intrinsic
-   Copyright 2002 Free Software Foundation, Inc.
+   Copyright 2002, 2005 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
@@ -78,6 +78,12 @@ eoshift3_8 (gfc_array_char *ret, gfc_arr
   GFC_INTEGER_8 sh;
   GFC_INTEGER_8 delta;
 
+  /* The compiler cannot figure out that these are set, initialize
+     them to avoid warnings.  */
+  len = 0;
+  soffset = 0;
+  roffset = 0;
+
   if (pwhich)
     which = *pwhich - 1;
   else
============================================================
Index: libgfortran/m4/eoshift1.m4
--- m4/eoshift1.m4	4 May 2005 21:38:15 -0000	1.7
+++ m4/eoshift1.m4	15 May 2005 12:38:45 -0000
@@ -1,5 +1,5 @@
 `/* Implementation of the EOSHIFT intrinsic
-   Copyright 2002 Free Software Foundation, Inc.
+   Copyright 2002, 2005 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
@@ -77,6 +77,12 @@ eoshift1_`'atype_kind (const gfc_array_c
   atype_name sh;
   atype_name delta;
 
+  /* The compiler cannot figure out that these are set, initialize
+     them to avoid warnings.  */
+  len = 0;
+  soffset = 0;
+  roffset = 0;
+
   if (pwhich)
     which = *pwhich - 1;
   else
============================================================
Index: libgfortran/m4/eoshift3.m4
--- m4/eoshift3.m4	4 May 2005 21:38:15 -0000	1.7
+++ m4/eoshift3.m4	15 May 2005 12:38:46 -0000
@@ -1,5 +1,5 @@
 `/* Implementation of the EOSHIFT intrinsic
-   Copyright 2002 Free Software Foundation, Inc.
+   Copyright 2002, 2005 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
@@ -79,6 +79,12 @@ eoshift3_`'atype_kind (gfc_array_char *r
   atype_name sh;
   atype_name delta;
 
+  /* The compiler cannot figure out that these are set, initialize
+     them to avoid warnings.  */
+  len = 0;
+  soffset = 0;
+  roffset = 0;
+
   if (pwhich)
     which = *pwhich - 1;
   else
============================================================
Index: libgfortran/intrinsics/spread_generic.c
--- intrinsics/spread_generic.c	4 May 2005 21:38:15 -0000	1.8
+++ intrinsics/spread_generic.c	15 May 2005 12:38:46 -0000
@@ -1,5 +1,5 @@
 /* Generic implementation of the SPREAD intrinsic
-   Copyright 2002 Free Software Foundation, Inc.
+   Copyright 2002, 2005 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
@@ -45,7 +45,7 @@ spread (gfc_array_char *ret, const gfc_a
   /* r.* indicates the return array.  */
   index_type rstride[GFC_MAX_DIMENSIONS];
   index_type rstride0;
-  index_type rdelta;
+  index_type rdelta = 0;
   index_type rrank;
   index_type rs;
   char *rptr;
============================================================
Index: libgfortran/intrinsics/eoshift0.c
--- intrinsics/eoshift0.c	4 May 2005 21:38:15 -0000	1.10
+++ intrinsics/eoshift0.c	15 May 2005 12:38:46 -0000
@@ -1,5 +1,5 @@
 /* Generic implementation of the EOSHIFT intrinsic
-   Copyright 2002 Free Software Foundation, Inc.
+   Copyright 2002, 2005 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
@@ -64,6 +64,12 @@ eoshift0 (gfc_array_char * ret, const gf
   index_type len;
   index_type n;
 
+  /* The compiler cannot figure out that these are set, initialize
+     them to avoid warnings.  */
+  len = 0;
+  soffset = 0;
+  roffset = 0;
+
   if (!pbound)
     pbound = zeros;
 
============================================================
Index: libgfortran/io/list_read.c
--- io/list_read.c	23 Apr 2005 12:38:08 -0000	1.18
+++ io/list_read.c	15 May 2005 12:38:46 -0000
@@ -2026,8 +2026,8 @@ nml_get_obj_data (void)
   char c;
   char * ext_name;
   namelist_info * nl;
-  namelist_info * first_nl;
-  namelist_info * root_nl;
+  namelist_info * first_nl = NULL;
+  namelist_info * root_nl = NULL;
   int dim;
   int component_flag;
 
-- 
 Andreas Jaeger, aj@suse.de, http://www.suse.de/~aj
  SUSE Linux Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126

Attachment: pgp00001.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]