]> granicus.if.org Git - flex/commitdiff
alloc routines take unsigned
authorVern Paxson <vern@ee.lbl.gov>
Wed, 15 Dec 1993 10:23:16 +0000 (10:23 +0000)
committerVern Paxson <vern@ee.lbl.gov>
Wed, 15 Dec 1993 10:23:16 +0000 (10:23 +0000)
flexdef.h
misc.c

index b9046c242cb781e2533f0e8e84db5329add5e8bd..b0f5fe62fd106dd959ce2e54e32fa6ee86c077a4 100644 (file)
--- a/flexdef.h
+++ b/flexdef.h
@@ -606,8 +606,8 @@ extern int num_backing_up, bol_needed;
 void *allocate_array PROTO((int, int));
 void *reallocate_array PROTO((void*, int, int));
 
-void *yy_flex_alloc PROTO((int));
-void *yy_flex_realloc PROTO((void*, int));
+void *yy_flex_alloc PROTO((unsigned int));
+void *yy_flex_realloc PROTO((void*, unsigned int));
 void yy_flex_free PROTO((void*));
 int yy_flex_strcmp PROTO(( const char *s1, const char *s2 ));
 void yy_flex_strcpy PROTO(( char *s1, const char *s2 ));
diff --git a/misc.c b/misc.c
index af7e5fdeca528f70faaa340cafc086e59070427c..271a3a401a46d53c294cad5f6366979151bce0a9 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -62,14 +62,7 @@ void *allocate_array( size, element_size )
 int size, element_size;
        {
        register void *mem;
-       int num_bytes = element_size * size;
-
-       /* On 16-bit int machines (e.g., 80286) we might be trying to
-        * allocate more than a signed int can hold, and that won't
-        * work.  Cheap test:
-        */
-       if ( num_bytes <= 0 )
-               flexfatal( "request for < 1 byte in allocate_array()" );
+       unsigned int num_bytes = element_size * size;
 
        mem = yy_flex_alloc( num_bytes );
 
@@ -178,12 +171,14 @@ register char *str;
        {
        register char *c;
        char *copy;
+       unsigned int size;
 
        /* find length */
        for ( c = str; *c; ++c )
                ;
 
-       copy = (char *) yy_flex_alloc( (c - str + 1) * sizeof( char ) );
+       size = (c - str + 1) * sizeof( char );
+       copy = (char *) yy_flex_alloc( size );
 
        if ( copy == NULL )
                flexfatal( "dynamic memory failure in copy_string()" );
@@ -750,12 +745,7 @@ void *array;
 int size, element_size;
        {
        register void *new_array;
-       int num_bytes = element_size * size;
-
-       /* Same worry as in allocate_array(): */
-       if ( num_bytes <= 0 )
-               flexfatal(
-                       "attempt to increase array size by less than 1 byte" );
+       unsigned int num_bytes = element_size * size;
 
        new_array = yy_flex_realloc( array, num_bytes );
 
@@ -855,7 +845,7 @@ int element_v, element_n;
 void *yy_flex_xmalloc( size )
 int size;
        {
-       void *result = yy_flex_alloc( size );
+       void *result = yy_flex_alloc( (unsigned) size );
 
        if ( ! result  )
                flexfatal( "memory allocation failed in yy_flex_xmalloc()" );