libgcrypt/src (ChangeLog global.c stdmem.c)

cvs user wk cvs at cvs.gnupg.org
Tue Feb 22 18:38:12 CET 2005


    Date: Tuesday, February 22, 2005 @ 18:49:27
  Author: wk
    Path: /cvs/libgcrypt/libgcrypt/src

Modified: ChangeLog global.c stdmem.c

(_gcry_malloc): Make sure ERRNO is set if we return
NULL.  Remove unneeded initialization of M to allow the compiler
to catch errors.
(gcry_realloc): Make sure ERRNO is set if we return NULL>


-----------+
 ChangeLog |    9 ++++++++-
 global.c  |   26 +++++++++++++++++++-------
 stdmem.c  |    4 ++--
 3 files changed, 29 insertions(+), 10 deletions(-)


Index: libgcrypt/src/ChangeLog
diff -u libgcrypt/src/ChangeLog:1.159 libgcrypt/src/ChangeLog:1.160
--- libgcrypt/src/ChangeLog:1.159	Sun Feb 13 19:13:22 2005
+++ libgcrypt/src/ChangeLog	Tue Feb 22 18:49:27 2005
@@ -1,3 +1,10 @@
+2005-02-22  Werner Koch  <wk at g10code.com>
+
+	* global.c (_gcry_malloc): Make sure ERRNO is set if we return
+	NULL.  Remove unneeded initialization of M to allow the compiler
+	to catch errors.
+	(gcry_realloc): Make sure ERRNO is set if we return NULL>
+
 2005-02-13  Moritz Schulte  <moritz at g10code.com>
 
 	* gcrypt.h: Declare new functions: gcry_ac_data_encrypt_scheme,
@@ -1393,7 +1400,7 @@
 
 	
  Copyright (C) 1998,1999,2000,2001,2002,2003
-	       2004 Free Software Foundation, Inc.
+	       2004, 2005 Free Software Foundation, Inc.
 
  This file is free software; as a special exception the author gives
  unlimited permission to copy and/or distribute it, with or without
Index: libgcrypt/src/global.c
diff -u libgcrypt/src/global.c:1.47 libgcrypt/src/global.c:1.48
--- libgcrypt/src/global.c:1.47	Mon Aug 23 15:34:51 2004
+++ libgcrypt/src/global.c	Tue Feb 22 18:49:27 2005
@@ -1,6 +1,6 @@
 /* global.c  -	global control functions
  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
- *               2004  Free Software Foundation, Inc.
+ *               2004, 2005  Free Software Foundation, Inc.
  *
  * This file is part of Libgcrypt.
  *
@@ -386,8 +386,8 @@
 gcry_err_code_t
 _gcry_malloc (size_t n, unsigned int flags, void **mem)
 {
-  gcry_err_code_t err = GPG_ERR_NO_ERROR;
-  void *m = NULL;
+  gcry_err_code_t err = 0;
+  void *m;
 
   if ((flags & GCRY_ALLOC_FLAG_SECURE) && !no_secure_memory)
     {
@@ -404,8 +404,14 @@
 	m = _gcry_private_malloc (n);
     }
 
-  if (! m)
-    err = gpg_err_code_from_errno (ENOMEM);
+  if (!m)
+    {
+      /* Make sure that ERRNO has been set in case a user supplied
+         memory handler didn't it correctly. */
+      if (!errno)
+        errno = ENOMEM;
+      err = gpg_err_code_from_errno (errno);
+    }
   else
     *mem = m;
 
@@ -457,9 +463,15 @@
 void *
 gcry_realloc (void *a, size_t n)
 {
+  void *p;
+
   if (realloc_func)
-    return realloc_func (a, n);
-  return _gcry_private_realloc (a, n);
+    p = realloc_func (a, n);
+  else
+    p =  _gcry_private_realloc (a, n);
+  if (!p && !errno)
+    errno = ENOMEM;
+  return p;
 }
 
 void
Index: libgcrypt/src/stdmem.c
diff -u libgcrypt/src/stdmem.c:1.10 libgcrypt/src/stdmem.c:1.11
--- libgcrypt/src/stdmem.c:1.10	Mon Jun  9 15:47:04 2003
+++ libgcrypt/src/stdmem.c	Tue Feb 22 18:49:27 2005
@@ -108,8 +108,8 @@
 
 
 /****************
- * realloc and clear the old space
- * Return NULL if there is not enoug memory.
+ * Realloc and clear the old space
+ * Return NULL if there is not enough memory.
  */
 void *
 _gcry_private_realloc( void *a, size_t n )




More information about the Gnupg-commits mailing list