diff src/dynamicstring.c @ 59:e612b263934f noffle

[svn] Changed some variable types and used some casts to avoid compiler warnings about signedness. In general, int should be used for parameters for allowing a signedness assertion in the function.
author enz
date Fri, 12 May 2000 17:52:41 +0100
parents 125d79c9e586
children 24d4cd032da5
line wrap: on
line diff
--- a/src/dynamicstring.c	Fri May 12 17:52:07 2000 +0100
+++ b/src/dynamicstring.c	Fri May 12 17:52:41 2000 +0100
@@ -1,7 +1,7 @@
 /*
   dynamicstring.c
 
-  $Id: dynamicstring.c 60 2000-05-09 22:28:38Z uh1763 $
+  $Id: dynamicstring.c 65 2000-05-12 16:52:41Z enz $
 */
 
 #if HAVE_CONFIG_H
@@ -16,17 +16,18 @@
 
 struct DynStr
 {
-    size_t len; /* Current length (without trailing '\0') */
-    size_t max; /* Max length that fits into buffer (incl. trailing '\0') */
+    int len; /* Current length (without trailing '\0') */
+    int max; /* Max length that fits into buffer (incl. trailing '\0') */
     char *str;
 };
 
 static void
-reallocStr( DynStr *self, size_t max )
+reallocStr( DynStr *self, int max )
 {
+    ASSERT( max >= 0 );
     if ( max <= self->max )
         return;
-    if ( ! ( self->str = (char *)realloc( self->str, max ) ) )
+    if ( ! ( self->str = (char *)realloc( self->str, (size_t)max ) ) )
     {
         Log_err( "Realloc of DynStr failed" );
         exit( EXIT_FAILURE );
@@ -37,7 +38,7 @@
 }
 
 DynStr *
-new_DynStr( size_t reserve )
+new_DynStr( int reserve )
 {
     DynStr *s;
     
@@ -64,7 +65,7 @@
     free( self );
 }
 
-size_t
+int
 DynStr_len( const DynStr *self )
 {
     return self->len;
@@ -79,7 +80,7 @@
 void
 DynStr_app( DynStr *self, const char *s )
 {
-    size_t len;
+    int len;
 
     len = strlen( s );
     if ( self->len + len + 1 > self->max )
@@ -93,7 +94,7 @@
 {
     if ( self->len + s->len + 1 > self->max )
         reallocStr( self, self->len * 2 + s->len + 1 );
-    memcpy( self->str + self->len, s->str, s->len + 1 );
+    memcpy( self->str + self->len, s->str, (size_t)s->len + 1 );
     self->len += s->len;
 }
 
@@ -105,13 +106,14 @@
 }
 
 void
-DynStr_appN( DynStr *self, const char *s, size_t n )
+DynStr_appN( DynStr *self, const char *s, int n )
 {
-    size_t len = self->len;
+    int len = self->len;
 
+    ASSERT( n >= 0 );
     if ( len + n + 1 > self->max )
         reallocStr( self, len * 2 + n + 1 );
-    strncat( self->str + len, s, n );
+    strncat( self->str + len, s, (size_t)n );
     self->len = len + strlen( self->str + len );
 }