changeset 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 31edce4598d0
files os2/dw.c win/dw.c
diffstat 2 files changed, 99 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/os2/dw.c	Sat Jun 30 19:53:18 2012 +0000
+++ b/os2/dw.c	Sun Jul 01 07:51:25 2012 +0000
@@ -7710,12 +7710,14 @@
       HWND frame = (HWND)dw_window_get_data(item, "_dw_combo_box");
 
       /* 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++)
       {
@@ -7725,7 +7727,6 @@
          x++;
       }
 
-
       WinQueryClassName(item, 99, (PCH)tmpbuf);
 
       if(vsize && !height)
@@ -7758,7 +7759,7 @@
 
       thisbox->items = tmpitem;
 
-      if(thisbox->count)
+      if(thisitem)
          free(thisitem);
 
       thisbox->count++;
@@ -7798,8 +7799,11 @@
       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++)
          {
             if(thisitem[z].hwnd == handle)
@@ -7809,21 +7813,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;
+            
          /* If it isn't padding, reset the parent */
          if(handle)
             WinSetParent(handle, HWND_OBJECT, FALSE);
@@ -7851,24 +7863,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)
          WinSetParent(handle, HWND_OBJECT, FALSE);
--- 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);