]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - catgets/catgets.c
Add TCP_TX_DELAY from Linux 5.3 to netinet/tcp.h.
[thirdparty/glibc.git] / catgets / catgets.c
index b11cc597b300dc227e473d31942e2e8145ad0783..07f732583351455594190d87f4ec4af1ed57d782 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper, <drepper@gnu.org>.
 
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
 
-#include <alloca.h>
 #include <errno.h>
 #include <locale.h>
 #include <nl_types.h>
@@ -36,6 +34,7 @@ catopen (const char *cat_name, int flag)
   __nl_catd result;
   const char *env_var = NULL;
   const char *nlspath = NULL;
+  char *tmp = NULL;
 
   if (strchr (cat_name, '/') == NULL)
     {
@@ -55,7 +54,10 @@ catopen (const char *cat_name, int flag)
        {
          /* Append the system dependent directory.  */
          size_t len = strlen (nlspath) + 1 + sizeof NLSPATH;
-         char *tmp = alloca (len);
+         tmp = malloc (len);
+
+         if (__glibc_unlikely (tmp == NULL))
+           return (nl_catd) -1;
 
          __stpcpy (__stpcpy (__stpcpy (tmp, nlspath), ":"), NLSPATH);
          nlspath = tmp;
@@ -66,13 +68,18 @@ catopen (const char *cat_name, int flag)
 
   result = (__nl_catd) malloc (sizeof (*result));
   if (result == NULL)
-    /* We cannot get enough memory.  */
-    return (nl_catd) -1;
-
-  if (__open_catalog (cat_name, nlspath, env_var, result) != 0)
-    /* Couldn't open the file.  */
-    return (nl_catd) -1;
+    {
+      /* We cannot get enough memory.  */
+      result = (nl_catd) -1;
+    }
+  else if (__open_catalog (cat_name, nlspath, env_var, result) != 0)
+    {
+      /* Couldn't open the file.  */
+      free ((void *) result);
+      result = (nl_catd) -1;
+    }
 
+  free (tmp);
   return (nl_catd) result;
 }
 
@@ -95,8 +102,8 @@ catgets (nl_catd catalog_desc, int set, int message, const char *string)
   cnt = 0;
   do
     {
-      if (catalog->name_ptr[idx + 0] == (u_int32_t) set
-         && catalog->name_ptr[idx + 1] == (u_int32_t) message)
+      if (catalog->name_ptr[idx + 0] == (uint32_t) set
+         && catalog->name_ptr[idx + 1] == (uint32_t) message)
        return (char *) &catalog->strings[catalog->name_ptr[idx + 2]];
 
       idx += catalog->plane_size * 3;