diff options
Diffstat (limited to 'stringsort.c')
-rw-r--r-- | stringsort.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/stringsort.c b/stringsort.c index 7670dea..bf38981 100644 --- a/stringsort.c +++ b/stringsort.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <stdint.h> +#include <string.h> #include <math.h> #include <limits.h> @@ -52,10 +53,10 @@ void DoStringSort(void) { SortStruct *strsortstruct; /* Local for sort structure */ -unsigned char *arraybase; /* Base pointer of char array */ +unsigned char *arraybase = NULL; /* Base pointer of char array */ long accumtime; /* Accumulated time */ double iterations; /* # of iterations */ -char *errorcontext; /* Error context string pointer */ +char *context; /* Error context string pointer */ int systemerror; /* For holding error code */ /* @@ -66,7 +67,7 @@ strsortstruct=&global_strsortstruct; /* ** Set the error context */ -errorcontext="CPU:String Sort"; +context="CPU:String Sort"; /* ** See if we have to perform self-adjustment code @@ -84,10 +85,10 @@ if(strsortstruct->adjust==0) ** bytes to protect memory as strings move around ** (this can happen during string adjustment) */ - arraybase=(unsigned char *)AllocateMemory((strsortstruct->arraysize+100L) * - (long)strsortstruct->numarrays,&systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); + arraybase = realloc(arraybase, (strsortstruct->arraysize + 100) * strsortstruct->numarrays); + if (!arraybase) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + exit(1); } /* @@ -101,7 +102,6 @@ if(strsortstruct->adjust==0) strsortstruct->arraysize)>global_min_ticks) break; /* We're ok...exit */ - FreeMemory((void *)arraybase,&systemerror); strsortstruct->numarrays+=1; } } @@ -111,11 +111,11 @@ else ** We don't have to perform self adjustment code. ** Simply allocate the space for the array. */ - arraybase=(unsigned char *)AllocateMemory((strsortstruct->arraysize+100L) * - (long)strsortstruct->numarrays,&systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - } + arraybase = malloc((strsortstruct->arraysize + 100) * strsortstruct->numarrays); + if (!arraybase) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + exit(1); + } } /* ** All's well if we get here. Repeatedly perform sorts until the @@ -322,12 +322,11 @@ while(k<numarrays) ** Now the array is full, allocate enough space for an ** offset pointer array. */ -optrarray=(unsigned long *)AllocateMemory(*nstrings * sizeof(unsigned long) * - numarrays, - &systemerror); -if(systemerror) -{ ReportError("CPU:Stringsort",systemerror); - FreeMemory((void *)strarray,&systemerror); +optrarray = malloc(*nstrings * sizeof(unsigned long) * numarrays); +if (!optrarray) { + /* FIXME: add error message */ + free(strarray); + exit(1); } /* |