From 59791fa229a310f54998cba95b79d644ed370d4a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Fri, 8 Sep 2000 10:31:26 -0700
Subject: [PATCH] minor bugfix for add_mapping

Rev: src/mapping.c:1.103
---
 src/mapping.c | 50 +++++++++++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/src/mapping.c b/src/mapping.c
index f81531049d..2aa2f0750f 100644
--- a/src/mapping.c
+++ b/src/mapping.c
@@ -5,7 +5,7 @@
 \*/
 /**/
 #include "global.h"
-RCSID("$Id: mapping.c,v 1.102 2000/09/08 16:38:20 grubba Exp $");
+RCSID("$Id: mapping.c,v 1.103 2000/09/08 17:31:26 hubbe Exp $");
 #include "main.h"
 #include "object.h"
 #include "mapping.h"
@@ -1434,7 +1434,7 @@ PMOD_EXPORT struct mapping *merge_mapping_array_unordered(struct mapping *a,
 PMOD_EXPORT struct mapping *add_mappings(struct svalue *argp, INT32 args)
 {
   INT32 e,d;
-  struct mapping *ret;
+  struct mapping *ret=0;
   struct keypair *k;
 
   for(e=d=0;d<args;d++)
@@ -1456,32 +1456,40 @@ PMOD_EXPORT struct mapping *add_mappings(struct svalue *argp, INT32 args)
 
     if(md->size == 0) continue;
 
+    if(!(md->flags  && MAPPING_FLAG_WEAK))
+    {
 #if 1 /* major optimization */
-    if(e==md->size && !(md->flags && MAPPING_FLAG_WEAK))
-      return copy_mapping(m);
+      if(e==md->size)
+	return copy_mapping(m);
 #endif
     
-    if(m->refs == 1 && !md->hardlinks)
-    {
-      add_ref( ret=m );
-      d++;
-    }else{
-      ret=allocate_mapping(MAP_SLOTS(e));
+      if(m->refs == 1 && !md->hardlinks)
+      {
+	add_ref( ret=m );
+	d++;
+	break;
+      }
     }
+    ret=allocate_mapping(MAP_SLOTS(e));
+    break;
 
-    for(;d<args;d++)
-    {
-      m=argp[d].u.mapping;
-      md=m->data;
+  }
 
-      add_ref(md);
-      NEW_MAPPING_LOOP(md)
-	mapping_insert(ret, &k->ind, &k->val);
-      free_mapping_data(md);
-    }
-    return ret;
+  for(;d<args;d++)
+  {
+    struct mapping *m=argp[d].u.mapping;
+    struct mapping_data *md=m->data;
+    
+    add_ref(md);
+    NEW_MAPPING_LOOP(md)
+      mapping_insert(ret, &k->ind, &k->val);
+    free_mapping_data(md);
   }
-  fatal("add_mappings is confused!\n");
+#ifdef PIKE_DEBUG
+  if(!ret)
+    fatal("add_mappings is confused!\n");
+#endif
+  return ret;
 }
 
 PMOD_EXPORT int mapping_equal_p(struct mapping *a, struct mapping *b, struct processing *p)
-- 
GitLab