public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Fix check for empty locale string in newlocale
@ 2016-10-22 19:10 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2016-10-22 19:10 UTC (permalink / raw)
  To: newlib-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=34aded1f54da8e3035275bce3196cb607d3e386c

commit 34aded1f54da8e3035275bce3196cb607d3e386c
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Sat Oct 22 20:22:20 2016 +0200

    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>

Diff:
---
 newlib/libc/locale/newlocale.c | 7 +++++--
 1 file 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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-10-22 19:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-22 19:10 [newlib-cygwin] Fix check for empty locale string in newlocale Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).