From c055789c50dd1362b80a7571e01c7edc2c1d246d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Tue, 11 May 1999 21:40:08 -0700
Subject: [PATCH] patch for malloc(0) returning 0

Rev: src/builtin_functions.c:1.170
---
 src/builtin_functions.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/builtin_functions.c b/src/builtin_functions.c
index beae1c977c..ce7c020526 100644
--- a/src/builtin_functions.c
+++ b/src/builtin_functions.c
@@ -5,7 +5,7 @@
 \*/
 /**/
 #include "global.h"
-RCSID("$Id: builtin_functions.c,v 1.169 1999/05/11 18:56:32 mirar Exp $");
+RCSID("$Id: builtin_functions.c,v 1.170 1999/05/12 04:40:08 hubbe Exp $");
 #include "interpret.h"
 #include "svalue.h"
 #include "pike_macros.h"
@@ -2614,6 +2614,9 @@ static struct array *longest_ordered_sequence(struct array *a)
   ONERROR tmp;
   ONERROR tmp2;
 
+  if(!a->size)
+    return allocate_array(0);
+
   stack = malloc(sizeof(int)*a->size);
   links = malloc(sizeof(int)*a->size);
 
@@ -2906,6 +2909,9 @@ static struct array *diff_longest_sequence(struct array *cmptbl, int blen)
    struct diff_magic_link **stack;
    char *marks;
 
+   if(!cmptbl->size)
+     return allocate_array(0);
+
    stack = malloc(sizeof(struct diff_magic_link*)*cmptbl->size);
 
    if (!stack) {
@@ -2918,7 +2924,7 @@ static struct array *diff_longest_sequence(struct array *cmptbl, int blen)
    /* NB: marks is used for optimization purposes only */
    marks = calloc(blen, 1);
 
-   if (!marks) {
+   if (!marks && blen) {
      int args = 0;
      free(stack);
      SIMPLE_OUT_OF_MEMORY_ERROR("diff_longest_sequence", blen);
-- 
GitLab