aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/locale
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2016-10-22 20:22:20 +0200
committerCorinna Vinschen <corinna@vinschen.de>2016-10-22 20:22:20 +0200
commit34aded1f54da8e3035275bce3196cb607d3e386c (patch)
treeb9c5d4490667a2176f41881cb7b1971fb98ff394 /newlib/libc/locale
parentdda82d1a7be51719013dd2c9d255a2e7790eed53 (diff)
downloadnewlib-34aded1f54da8e3035275bce3196cb607d3e386c.zip
newlib-34aded1f54da8e3035275bce3196cb607d3e386c.tar.gz
newlib-34aded1f54da8e3035275bce3196cb607d3e386c.tar.bz2
Fix check for empty locale string in newlocale
The original test is broken. It tests for a NULL locale which isn't just wrong, it simply can't occur at this point due to an earlier check for a NULL locale string. Thus, the locale info for a category is never taken from the environment. Fixes Coverty CID 153467. Also, add comment. Also, add some parens for readability. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'newlib/libc/locale')
-rw-r--r--newlib/libc/locale/newlocale.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/newlib/libc/locale/newlocale.c b/newlib/libc/locale/newlocale.c
index bd4e385..c817625 100644
--- a/newlib/libc/locale/newlocale.c
+++ b/newlib/libc/locale/newlocale.c
@@ -101,7 +101,7 @@ _newlocale_r (struct _reent *p, int category_mask, const char *locale,
category_mask |= LC_VALID_MASK;
}
/* Check for invalid mask values and valid locale ptr. */
- if (category_mask & ~LC_VALID_MASK || !locale)
+ if ((category_mask & ~LC_VALID_MASK) || !locale)
{
p->_errno = EINVAL;
return NULL;
@@ -119,7 +119,10 @@ _newlocale_r (struct _reent *p, int category_mask, const char *locale,
{
if (((1 << i) & category_mask) != 0)
{
- const char *cat = locale ?: __get_locale_env (p, i);
+ /* If locale is "", fetch from environment. Otherwise use locale
+ name verbatim. */
+ const char *cat = (locale[0] == '\0') ? __get_locale_env (p, i)
+ : locale;
if (strlen (cat) > ENCODING_LEN)
{
p->_errno = EINVAL;