tFixes for dodgy memory handling in Win32 installer - vaccinewars - be a doctor and try to vaccinate the world
 (HTM) git clone git://src.adamsgaard.dk/vaccinewars
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 88feb29ac0e7cbce3c3f4f1a9aaaaa84fb1e1d7f
 (DIR) parent aa38d66d5be2f4de64e3beb58c67937ebd7bcc93
 (HTM) Author: Ben Webb <ben@salilab.org>
       Date:   Thu,  4 Oct 2001 19:17:51 +0000
       
       Fixes for dodgy memory handling in Win32 installer
       
       
       Diffstat:
         M win32/util.c                        |      36 ++++++++++++-------------------
       
       1 file changed, 14 insertions(+), 22 deletions(-)
       ---
 (DIR) diff --git a/win32/util.c b/win32/util.c
       t@@ -35,22 +35,16 @@ void *brealloc(void *pt,UINT numbytes) {
          UINT numcp;
          void *newpt;
          if (!pt && numbytes) return bmalloc(numbytes);
       -  else if (pt && !numbytes) bfree(pt);
       -  else if (pt && numbytes) {
       -    localpt = LocalReAlloc((HLOCAL)pt,numbytes,0);
       -    if (localpt) return (void *)localpt;
       -    else if (GetLastError()==ERROR_LOCKED) { /* OK, we'll do it the hard way */
       -      newpt=bmalloc(numbytes);
       -      memset(newpt,0,numbytes);
       -      numcp = LocalSize((HLOCAL)pt);
       -      if (numbytes < numcp) numcp = numbytes;
       -      memcpy((char *)newpt,(char *)pt,numcp);
       -      bfree(pt);
       -      return newpt;
       -    } else {
       -      DisplayError("Could not reallocate memory: ",TRUE,TRUE);
       -      ExitProcess(1);
       -    }
       +  else if (pt && !numbytes) {
       +    bfree(pt);
       +  } else if (pt && numbytes) {
       +    newpt=bmalloc(numbytes);
       +    memset(newpt,0,numbytes);
       +    numcp = LocalSize((HLOCAL)pt);
       +    if (numbytes < numcp) numcp = numbytes;
       +    memcpy((char *)newpt,(char *)pt,numcp);
       +    bfree(pt);
       +    return newpt;
          }
          return NULL;
        }
       t@@ -90,13 +84,11 @@ void bstr_expandby(bstr *str,unsigned extralength) {
        }
        
        void bstr_setlength(bstr *str,unsigned length) {
       -  if (length+1 <= str->bufsiz) {
       -    if (length < str->length) {
       -      str->length = length;
       -      str->text[length]='\0';
       -    }
       +  if (length <= str->length) {
       +    str->length = length;
       +    str->text[length]='\0';
          } else {
       -    bstr_expandby(str,length+1-str->bufsiz);
       +    bstr_expandby(str,length-str->length);
          }
        }