mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-20 16:01:10 +08:00
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>
This commit is contained in:
parent
dda82d1a7b
commit
34aded1f54
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user