diff win/dw.c @ 1766:47e503ecc812

Ported clang/Xcode fixes to Windows and OS/2 just in case.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 01 Jul 2012 07:51:25 +0000
parents 15414cbe857f
children d81bebc5c8cc
line wrap: on
line diff
--- a/win/dw.c	Sat Jun 30 19:53:18 2012 +0000
+++ b/win/dw.c	Sun Jul 01 07:51:25 2012 +0000
@@ -7086,12 +7086,14 @@
       Item *tmpitem, *thisitem = thisbox->items;
 
       /* Do some sanity bounds checking */
+      if(!thisitem)
+          thisbox->count = 0;
       if(index < 0)
         index = 0;
       if(index > thisbox->count)
         index = thisbox->count;
 
-      tmpitem = malloc(sizeof(Item)*(thisbox->count+1));
+      tmpitem = calloc(sizeof(Item), (thisbox->count+1));
 
       for(z=0;z<thisbox->count;z++)
       {
@@ -7144,7 +7146,7 @@
 
       thisbox->items = tmpitem;
 
-      if(thisbox->count)
+      if(thisitem)
          free(thisitem);
 
       thisbox->count++;
@@ -7199,7 +7201,10 @@
       if(thisbox && thisbox->count)
       {
          int z, index = -1;
-         Item *tmpitem, *thisitem = thisbox->items;
+         Item *tmpitem = NULL, *thisitem = thisbox->items;
+
+         if(!thisitem)
+             thisbox->count = 0;
 
          for(z=0;z<thisbox->count;z++)
          {
@@ -7210,21 +7215,29 @@
          if(index == -1)
             return DW_ERROR_GENERAL;
 
-         tmpitem = malloc(sizeof(Item)*(thisbox->count-1));
-
-         /* Copy all but the current entry to the new list */
-         for(z=0;z<index;z++)
-         {
-            tmpitem[z] = thisitem[z];
-         }
-         for(z=index+1;z<thisbox->count;z++)
-         {
-            tmpitem[z-1] = thisitem[z];
+         if(thisbox->count > 1)
+         {
+            tmpitem = calloc(sizeof(Item), (thisbox->count-1));
+
+            /* Copy all but the current entry to the new list */
+            for(z=0;z<index;z++)
+            {
+               tmpitem[z] = thisitem[z];
+            }
+            for(z=index+1;z<thisbox->count;z++)
+            {
+               tmpitem[z-1] = thisitem[z];
+            }
          }
 
          thisbox->items = tmpitem;
-         free(thisitem);
-         thisbox->count--;
+         if(thisitem)
+            free(thisitem);
+         if(tmpitem)
+            thisbox->count--;
+         else
+            thisbox->count = 0;
+
          SetParent(handle, DW_HWND_OBJECT);
          /* Queue a redraw on the top-level window */
          _dw_redraw(_toplevel_window(parent), TRUE);
@@ -7250,24 +7263,32 @@
    if(thisbox && index > -1 && index < thisbox->count)
    {
       int z;
-      Item *tmpitem, *thisitem = thisbox->items;
+      Item *tmpitem = NULL, *thisitem = thisbox->items;
       HWND handle = thisitem[index].hwnd;
 
-      tmpitem = malloc(sizeof(Item)*(thisbox->count-1));
-
-      /* Copy all but the current entry to the new list */
-      for(z=0;z<index;z++)
-      {
-         tmpitem[z] = thisitem[z];
-      }
-      for(z=index+1;z<thisbox->count;z++)
-      {
-         tmpitem[z-1] = thisitem[z];
+      if(thisbox->count > 1)
+      {
+         tmpitem = calloc(sizeof(Item), (thisbox->count-1));
+
+         /* Copy all but the current entry to the new list */
+         for(z=0;z<index;z++)
+         {
+            tmpitem[z] = thisitem[z];
+         }
+         for(z=index+1;z<thisbox->count;z++)
+         {
+            tmpitem[z-1] = thisitem[z];
+         }
       }
 
       thisbox->items = tmpitem;
-      free(thisitem);
-      thisbox->count--;
+      if(thisitem)
+         free(thisitem);
+      if(tmpitem)
+         thisbox->count--;
+      else
+         thisbox->count = 0;
+
       /* If it isn't padding, reset the parent */
       if(handle)
          SetParent(handle, DW_HWND_OBJECT);