Hi,

This fixes two -Wshadow=local warnings, and a undefined behavior that is
used in the loop termination logic here:

for (p = c - 1; p >= buffer; p--)
  {
    if (*p == '.')
      continue;

In order to terminate the loop p is decremented until it points
to buffer-1 (buffer is alloca'd, so that is undefined behavior.

I changed that loop to
for (p = c; p > buffer;)
  {
    p--;
    if (*p == '.')
      continue;

There are a lot more -Wshadow=local warnings in the fortran subtree,
but they are not bug fixes, so I plan to commit them in the
following days, as obvious.


Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?


Thanks
Bernd.

2019-10-03  Bernd Edlinger  <bernd.edlin...@hotmail.de>

	* primary.c (match_real_constant): Remove shadowing local vars.
	Rename local vars.  Fix undefined behavior in loop termination.
	(gfc_convert_to_structure_constructor): Rename local var.

Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c	(revision 276484)
+++ gcc/fortran/primary.c	(working copy)
@@ -789,16 +789,17 @@ done:
   if (warn_conversion_extra)
     {
       mpfr_t r;
-      char *c, *p;
+      char *c1;
       bool did_break;
 
-      c = strchr (buffer, 'e');
-      if (c == NULL)
-	c = buffer + strlen(buffer);
+      c1 = strchr (buffer, 'e');
+      if (c1 == NULL)
+	c1 = buffer + strlen(buffer);
 
       did_break = false;
-      for (p = c - 1; p >= buffer; p--)
+      for (p = c1; p > buffer;)
 	{
+	  p--;
 	  if (*p == '.')
 	    continue;
 
@@ -3099,21 +3100,21 @@ gfc_convert_to_structure_constructor (gfc_expr *e,
 	  && actual->expr->ts.type == BT_CHARACTER
 	  && actual->expr->expr_type == EXPR_CONSTANT)
 	{
-	  ptrdiff_t c, e;
+	  ptrdiff_t c, e1;
 	  c = gfc_mpz_get_hwi (this_comp->ts.u.cl->length->value.integer);
-	  e = actual->expr->value.character.length;
+	  e1 = actual->expr->value.character.length;
 
-	  if (c != e)
+	  if (c != e1)
 	    {
 	      ptrdiff_t i, to;
 	      gfc_char_t *dest;
 	      dest = gfc_get_wide_string (c + 1);
 
-	      to = e < c ? e : c;
+	      to = e1 < c ? e1 : c;
 	      for (i = 0; i < to; i++)
 		dest[i] = actual->expr->value.character.string[i];
 
-	      for (i = e; i < c; i++)
+	      for (i = e1; i < c; i++)
 		dest[i] = ' ';
 
 	      dest[c] = '\0';
@@ -3122,11 +3123,11 @@ gfc_convert_to_structure_constructor (gfc_expr *e,
 	      actual->expr->value.character.length = c;
 	      actual->expr->value.character.string = dest;
 
-	      if (warn_line_truncation && c < e)
+	      if (warn_line_truncation && c < e1)
 		gfc_warning_now (OPT_Wcharacter_truncation,
 				 "CHARACTER expression will be truncated "
 				 "in constructor (%ld/%ld) at %L", (long int) c,
-				 (long int) e, &actual->expr->where);
+				 (long int) e1, &actual->expr->where);
 	    }
 	}
 

Reply via email to