]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
(request2size): Also set errno if failing.
authorUlrich Drepper <drepper@redhat.com>
Thu, 8 Jul 1999 11:49:00 +0000 (11:49 +0000)
committerUlrich Drepper <drepper@redhat.com>
Thu, 8 Jul 1999 11:49:00 +0000 (11:49 +0000)
(request2size): Take care of overflow in addition.

malloc/malloc.c

index e096f00eebcee41f3da41d830c6d28f96658c69e..31ab045a065009ccb0fe41355404eef7676c5579 100644 (file)
 extern "C" {
 #endif
 
+#include <errno.h>
 #include <stdio.h>    /* needed for malloc_stats */
 
 
@@ -822,6 +823,10 @@ do {                                                                          \
    computed. */
 
 
+/* Macro to set errno.  */
+#ifndef __set_errno
+# define __set_errno(val) errno = (val)
+#endif
 
 /* On some platforms we can compile internal, not exported functions better.
    Let the environment provide a macro and define it to be empty if it
@@ -1263,8 +1268,10 @@ static void      free_atfork();
 
 #define request2size(req, nb) \
  ((nb = (req) + (SIZE_SZ + MALLOC_ALIGN_MASK)),\
-  ((long)nb <= 0 ? 1 : ((nb < (MINSIZE + MALLOC_ALIGN_MASK) ? (nb = MINSIZE) :\
-                         (nb &= ~MALLOC_ALIGN_MASK)), 0)))
+  ((long)nb <= 0 || nb < (INTERNAL_SIZE_T) (req) \
+   ? (__set_errno (ENOMEM), 1) \
+   : ((nb < (MINSIZE + MALLOC_ALIGN_MASK) \
+          ? (nb = MINSIZE) : (nb &= ~MALLOC_ALIGN_MASK)), 0)))
 
 /* Check if m has acceptable alignment */