[MIPS] Returning array literal from find_translit2

Message ID 4cd4f5d8-d93b-47ff-b039-9fbef4d9ee37@BAMAIL02.ba.imgtec.org
State Superseded
Headers

Commit Message

Steve Ellcey Dec. 11, 2014, 5:57 p.m. UTC
  Here is another warning/error I get from locale/programs/ld-ctype.c when
building glibc on MIPS:


programs/ld-ctype.c: In function 'find_translit':
cc1: error: function may return address of local variable [-Werror=return-local-addr]
programs/ld-ctype.c:1780:29: note: declared here
        return (uint32_t []) { 0 };
                             ^
cc1: error: function may return address of local variable [-Werror=return-local-addr]
programs/ld-ctype.c:1780:29: note: declared here
cc1: all warnings being treated as errors



My proposed fix is to create a static global that can be returned instead
of the array literal.  Does this look like the right way to fix this?
Is there a better name than zero to use?

I tested it with no regressions, OK to checkin?


2014-12-11  Steve Ellcey  <sellcey@imgtec.com>

	* locale/programs/ld-ctype.c (zero): New static global variable.
	(find_translit2): Return zero instead of array literal.
  

Comments

Joseph Myers Dec. 11, 2014, 5:59 p.m. UTC | #1
On Thu, 11 Dec 2014, Steve Ellcey  wrote:

> 2014-12-11  Steve Ellcey  <sellcey@imgtec.com>
> 
> 	* locale/programs/ld-ctype.c (zero): New static global variable.
> 	(find_translit2): Return zero instead of array literal.

Please follow up to 
<https://sourceware.org/ml/libc-alpha/2014-12/msg00287.html>.
  

Patch

diff --git a/locale/programs/ld-ctype.c b/locale/programs/ld-ctype.c
index 67846b3..01de017 100644
--- a/locale/programs/ld-ctype.c
+++ b/locale/programs/ld-ctype.c
@@ -1724,6 +1724,7 @@  to-value character sequence is smaller than from-value sequence"));
     }
 }
 
+static uint32_t zero[] = { 0 };
 
 static uint32_t *
 find_translit2 (struct locale_ctype_t *ctype, const struct charmap_t *charmap,
@@ -1777,7 +1778,7 @@  find_translit2 (struct locale_ctype_t *ctype, const struct charmap_t *charmap,
 
 	  for (wi = tirunp->from; wi <= wch; wi += tirunp->step)
 	    if (wi == wch)
-	      return (uint32_t []) { 0 };
+	      return zero;
 	}
     }