[MIPS] Returning array literal from find_translit2
Commit Message
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
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>.
@@ -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;
}
}