changeset 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 b4e6f7f96135
children defaa632baae
files src/content.c src/dynamicstring.c src/dynamicstring.h src/protocol.c src/util.c src/util.h
diffstat 6 files changed, 40 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/content.c	Fri May 12 17:52:07 2000 +0100
+++ b/src/content.c	Fri May 12 17:52:41 2000 +0100
@@ -1,7 +1,7 @@
 /*
   content.c
 
-  $Id: content.c 60 2000-05-09 22:28:38Z uh1763 $
+  $Id: content.c 65 2000-05-12 16:52:41Z enz $
 */
 
 #if HAVE_CONFIG_H
@@ -31,8 +31,8 @@
     int vecFirst;	/* First article number in vector */
     int first;		/* First live article number */
     int last;		/* Last article number */
-    unsigned int size;  /* Number of overviews. */
-    unsigned int max;   /* Size of elem. */
+    int size;           /* Number of overviews. */
+    int max;            /* Size of elem. */
     Over **elem;        /* Ptr to array with ptrs to overviews.
                            NULL entries for non-existing article numbers
                            in group. */
--- 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 );
 }
 
--- a/src/dynamicstring.h	Fri May 12 17:52:07 2000 +0100
+++ b/src/dynamicstring.h	Fri May 12 17:52:41 2000 +0100
@@ -3,7 +3,7 @@
 
   String utilities
 
-  $Id: dynamicstring.h 51 2000-05-05 23:49:38Z uh1763 $
+  $Id: dynamicstring.h 65 2000-05-12 16:52:41Z enz $
 */
 
 #ifndef DYNAMICSTRING_H
@@ -21,14 +21,14 @@
 
 /* Create new DynStr with given capacity */
 DynStr *
-new_DynStr( size_t reserve );
+new_DynStr( int reserve );
 
 /* Delete DynStr */
 void
 del_DynStr( DynStr *self );
 
 /* Return DynStr's length */
-size_t
+int
 DynStr_len( const DynStr *self );
 
 /* Return DynStr's content ptr */
@@ -49,7 +49,7 @@
 
 /* Append a maximum of n characters from C-string s to DynStr self */
 void
-DynStr_appN( DynStr *self, const char *s, size_t n );
+DynStr_appN( DynStr *self, const char *s, int n );
 
 /* Truncate content of DynString to zero length */
 void
--- a/src/protocol.c	Fri May 12 17:52:07 2000 +0100
+++ b/src/protocol.c	Fri May 12 17:52:41 2000 +0100
@@ -1,7 +1,7 @@
 /*
   protocol.c
 
-  $Id: protocol.c 60 2000-05-09 22:28:38Z uh1763 $
+  $Id: protocol.c 65 2000-05-12 16:52:41Z enz $
 */
 
 #if HAVE_CONFIG_H
@@ -76,12 +76,12 @@
     if ( line[ 0 ] == '.' )
     {
         Log_dbg( "[S] .%s", line );
-        return ( fprintf( f, ".%s\r\n", line ) == strlen( line ) + 3 );
+        return ( fprintf( f, ".%s\r\n", line ) == (int)strlen( line ) + 3 );
     }
     else
     {
         Log_dbg( "[S] %s", line );
-        return ( fprintf( f, "%s\r\n", line ) == strlen( line ) + 2 );
+        return ( fprintf( f, "%s\r\n", line ) == (int)strlen( line ) + 2 );
     }
 }
 
@@ -120,7 +120,7 @@
             /* Put it out raw to prevent String overflow */
             Log_err( "Writing VERY long line" );
             *pLn = '\0';
-            if ( fprintf( f, "%s", line ) != strlen( line ) )
+            if ( fprintf( f, "%s", line ) != (int)strlen( line ) )
                 return FALSE;
             pLn = line;
         }   
@@ -280,7 +280,7 @@
     getDomain( domain, from );
     time( &t );
     strftime( date, MAXCHAR, "%Y%m%d%H%M%S", gmtime( &t ) );
-    srand( time( NULL ) );
+    srand( (unsigned int)time( NULL ) );
     snprintf( msgId, MAXCHAR, "<%s.%X.%s@%s>", date, rand(), suffix, domain );
     ASSERT( Prt_isValidMsgId( msgId ) );
 }
--- a/src/util.c	Fri May 12 17:52:07 2000 +0100
+++ b/src/util.c	Fri May 12 17:52:41 2000 +0100
@@ -1,7 +1,7 @@
 /*
   util.c
 
-  $Id: util.c 60 2000-05-09 22:28:38Z uh1763 $
+  $Id: util.c 65 2000-05-12 16:52:41Z enz $
 */
 
 #if HAVE_CONFIG_H
@@ -195,12 +195,12 @@
 }
 
 void
-Utl_cpyStrN( Str dst, const char *src, size_t n )
+Utl_cpyStrN( Str dst, const char *src, int n )
 {
     if ( n > MAXCHAR )
     	n = MAXCHAR;
     dst[ 0 ] = '\0';
-    strncat( dst, src, n );
+    strncat( dst, src, (size_t)n );
 }
 
 void
@@ -210,11 +210,15 @@
 }
 
 void
-Utl_catStrN( Str dst, const char *src, size_t n )
+Utl_catStrN( Str dst, const char *src, int n )
 {
-    if ( n > MAXCHAR - strlen( dst ) )
-    	n = MAXCHAR - strlen( dst );
-    strncat( dst, src, n );
+    size_t un;
+
+    ASSERT( n >= 0 );
+    un = (size_t)n;
+    if ( un > MAXCHAR - strlen( dst ) )
+    	 un = MAXCHAR - strlen( dst );
+    strncat( dst, src, un );
 }
 
 void
--- a/src/util.h	Fri May 12 17:52:07 2000 +0100
+++ b/src/util.h	Fri May 12 17:52:41 2000 +0100
@@ -3,7 +3,7 @@
 
   Miscellaneous helper functions.
 
-  $Id: util.h 60 2000-05-09 22:28:38Z uh1763 $
+  $Id: util.h 65 2000-05-12 16:52:41Z enz $
 */
 
 #ifndef UTL_H
@@ -83,13 +83,13 @@
 Utl_cpyStr( Str dst, const char *src );
 
 void
-Utl_cpyStrN( Str dst, const char *src, size_t n );
+Utl_cpyStrN( Str dst, const char *src, int n );
 
 void
 Utl_catStr( Str dst, const char *src );
 
 void
-Utl_catStrN( Str dst, const char *src, size_t n );
+Utl_catStrN( Str dst, const char *src, int n );
 
 /* String allocation and copying. */
 void