From 4d17d6876e4b2f08380812c4ec113073b0a14639 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 29 Jan 2004 13:56:45 +0000 Subject: [PATCH] Dan Fandrich's cleanup patch to make pedantic compiler options cause less warnings. Minor edits by me. --- lib/connect.c | 1 + lib/content_encoding.c | 1 + lib/cookie.c | 20 ++++++++++---------- lib/dict.c | 1 + lib/escape.c | 16 ++++++++-------- lib/file.c | 1 + lib/formdata.c | 3 +++ lib/ftp.c | 4 ++-- lib/getdate.y | 36 ++++++++++++++---------------------- lib/getenv.c | 2 ++ lib/getinfo.c | 1 + lib/http.c | 10 +++++----- lib/http_chunks.c | 5 +++-- lib/http_chunks.h | 4 ++-- lib/if2ip.c | 2 ++ lib/inet_pton.c | 15 +++++---------- lib/ldap.c | 1 + lib/md5.c | 19 ++++++++++--------- lib/memdebug.c | 8 +++++--- lib/memdebug.h | 6 +++++- lib/mprintf.c | 2 ++ lib/netrc.c | 1 + lib/progress.c | 10 ++++++---- lib/sendf.c | 5 ++--- lib/share.c | 4 ++-- lib/ssluse.c | 5 +++-- lib/strequal.c | 2 ++ lib/strtok.c | 2 ++ lib/telnet.c | 1 + 29 files changed, 103 insertions(+), 85 deletions(-) diff --git a/lib/connect.c b/lib/connect.c index 33e16dd72..69f8ce374 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -76,6 +76,7 @@ #include "urldata.h" #include "sendf.h" #include "if2ip.h" +#include "connect.h" /* The last #include file should be: */ #ifdef CURLDEBUG diff --git a/lib/content_encoding.c b/lib/content_encoding.c index 1eb465161..4ccef4834 100644 --- a/lib/content_encoding.c +++ b/lib/content_encoding.c @@ -32,6 +32,7 @@ #include #include #include "sendf.h" +#include "content_encoding.h" #define DSIZ 0x10000 /* buffer size for decompressed data */ diff --git a/lib/cookie.c b/lib/cookie.c index f6f842f66..fa6194448 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -211,7 +211,7 @@ Curl_cookie_add(struct SessionHandle *data, /* note that this name may or may not have a preceeding dot, but we don't care about that, we treat the names the same anyway */ - char *ptr=whatptr; + const char *domptr=whatptr; int dotcount=1; unsigned int i; @@ -224,15 +224,15 @@ Curl_cookie_add(struct SessionHandle *data, if('.' == whatptr[0]) /* don't count the initial dot, assume it */ - ptr++; + domptr++; do { - ptr = strchr(ptr, '.'); - if(ptr) { - ptr++; + domptr = strchr(domptr, '.'); + if(domptr) { + domptr++; dotcount++; } - } while(ptr); + } while(domptr); for(i=0; idomain=strdup(ptr); /* dont prefix with dots internally */ + const char *tailptr=whatptr; + if(tailptr[0] == '.') + tailptr++; + co->domain=strdup(tailptr); /* don't prefix w/dots internally */ co->tailmatch=TRUE; /* we always do that if the domain name was given */ } diff --git a/lib/dict.c b/lib/dict.c index 62d629821..a22fa5a4d 100644 --- a/lib/dict.c +++ b/lib/dict.c @@ -74,6 +74,7 @@ #include "progress.h" #include "strequal.h" +#include "dict.h" #define _MPRINTF_REPLACE /* use our functions only */ #include diff --git a/lib/escape.c b/lib/escape.c index 2ecec11b0..87a9f1b9e 100644 --- a/lib/escape.c +++ b/lib/escape.c @@ -44,7 +44,7 @@ char *curl_escape(const char *string, int length) char *testing_ptr = NULL; unsigned char in; int newlen = alloc; - int index=0; + int strindex=0; length = alloc-1; while(length--) { @@ -65,17 +65,17 @@ char *curl_escape(const char *string, int length) ns = testing_ptr; } } - sprintf(&ns[index], "%%%02X", in); + sprintf(&ns[strindex], "%%%02X", in); - index+=3; + strindex+=3; } else { /* just copy this */ - ns[index++]=in; + ns[strindex++]=in; } string++; } - ns[index]=0; /* terminate it */ + ns[strindex]=0; /* terminate it */ return ns; } @@ -88,7 +88,7 @@ char *curl_unescape(const char *string, int length) int alloc = (length?length:(int)strlen(string))+1; char *ns = malloc(alloc); unsigned char in; - int index=0; + int strindex=0; unsigned int hex; if( !ns ) { @@ -112,10 +112,10 @@ char *curl_unescape(const char *string, int length) alloc-=2; } - ns[index++] = in; + ns[strindex++] = in; string++; } - ns[index]=0; /* terminate it */ + ns[strindex]=0; /* terminate it */ return ns; } diff --git a/lib/file.c b/lib/file.c index 274f67550..2eeb52760 100644 --- a/lib/file.c +++ b/lib/file.c @@ -81,6 +81,7 @@ #include "progress.h" #include "sendf.h" #include "escape.h" +#include "file.h" #define _MPRINTF_REPLACE /* use our functions only */ #include diff --git a/lib/formdata.c b/lib/formdata.c index ecfb0e559..31d14feb4 100644 --- a/lib/formdata.c +++ b/lib/formdata.c @@ -118,6 +118,9 @@ Content-Disposition: form-data; name="FILECONTENT" #include +#ifndef CURL_OLDSTYLE +#define CURL_OLDSTYLE 1 /* enable deprecated prototype for curl_formparse */ +#endif #include #include "formdata.h" diff --git a/lib/ftp.c b/lib/ftp.c index 0123b7027..51159f894 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -2388,7 +2388,7 @@ CURLcode Curl_ftpsendf(struct connectdata *conn, bytes_written=0; write_len = strlen(s); - do { + while(1) { res = Curl_write(conn, conn->sock[FIRSTSOCKET], sptr, write_len, &bytes_written); @@ -2404,7 +2404,7 @@ CURLcode Curl_ftpsendf(struct connectdata *conn, } else break; - } while(1); + } return res; } diff --git a/lib/getdate.y b/lib/getdate.y index 41fb6f8d2..eb556835a 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -152,9 +152,6 @@ #define yytable Curl_gd_yytable #define yycheck Curl_gd_yycheck -static int yylex (); -static int yyerror (); - #define EPOCH 1970 #define HOUR(x) ((x) * 60) @@ -224,6 +221,11 @@ typedef struct _CURL_CONTEXT { enum _MERIDIAN Meridian; } +%{ +static int yylex (YYSTYPE *yylval, void *cookie); +static int yyerror (const char *s); +%} + %token tAGO tDAY tDAY_UNIT tDAYZONE tDST tHOUR_UNIT tID %token tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT %token tSEC_UNIT tSNUMBER tUNUMBER tYEAR_UNIT tZONE @@ -495,9 +497,9 @@ o_merid : /* NULL */ #include "getdate.h" #ifndef WIN32 /* the windows dudes don't need these, does anyone really? */ -extern struct tm *gmtime (); -extern struct tm *localtime (); -extern time_t mktime (); +extern struct tm *gmtime (const time_t *); +extern struct tm *localtime (const time_t *); +extern time_t mktime (struct tm *); #endif /* Month and day table. */ @@ -689,16 +691,13 @@ static TABLE const MilitaryTable[] = { /* ARGSUSED */ static int -yyerror (s) - char *s ATTRIBUTE_UNUSED; +yyerror (const char *s ATTRIBUTE_UNUSED) { return 0; } static int -ToHour (Hours, Meridian) - int Hours; - MERIDIAN Meridian; +ToHour (int Hours, MERIDIAN Meridian) { switch (Meridian) { @@ -725,8 +724,7 @@ ToHour (Hours, Meridian) } static int -ToYear (Year) - int Year; +ToYear (int Year) { if (Year < 0) Year = -Year; @@ -742,9 +740,7 @@ ToYear (Year) } static int -LookupWord (yylval, buff) - YYSTYPE *yylval; - char *buff; +LookupWord (YYSTYPE *yylval, char *buff) { register char *p; register char *q; @@ -864,9 +860,7 @@ LookupWord (yylval, buff) } static int -yylex (yylval, cookie) - YYSTYPE *yylval; - void *cookie; +yylex (YYSTYPE *yylval, void *cookie) { register unsigned char c; register char *p; @@ -1085,9 +1079,7 @@ curl_getdate (const char *p, const time_t *now) /* ARGSUSED */ int -main (ac, av) - int ac; - char *av[]; +main (int ac, char *av[]) { char buff[MAX_BUFF_LEN + 1]; time_t d; diff --git a/lib/getenv.c b/lib/getenv.c index 6de071e25..d29689fd1 100644 --- a/lib/getenv.c +++ b/lib/getenv.c @@ -35,6 +35,8 @@ #include #endif +#include + #ifdef CURLDEBUG #include "memdebug.h" #endif diff --git a/lib/getinfo.c b/lib/getinfo.c index 43e3d461d..81eb2c055 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -26,6 +26,7 @@ #include #include "urldata.h" +#include "getinfo.h" #include #include diff --git a/lib/http.c b/lib/http.c index c3862cded..fea11f59a 100644 --- a/lib/http.c +++ b/lib/http.c @@ -193,11 +193,11 @@ void Curl_http_auth_act(struct connectdata *conn) * authentication method. */ -CURLcode http_auth_headers(struct connectdata *conn, - char *request, - char *path, - bool *ready) /* set TRUE when the auth phase is - done and ready to do the *actual* +static CURLcode http_auth_headers(struct connectdata *conn, + char *request, + char *path, + bool *ready) /* set TRUE when the auth phase + is done and ready to do the *actual* request */ { CURLcode result = CURLE_OK; diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 38f2fd06f..70a48950a 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -34,6 +34,7 @@ #include "sendf.h" /* for the client write stuff */ #include "content_encoding.h" /* 08/29/02 jhrg */ +#include "http.h" #define _MPRINTF_REPLACE /* use our functions only */ #include @@ -99,8 +100,8 @@ void Curl_httpchunk_init(struct connectdata *conn) */ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap, - size_t length, - size_t *wrote) + ssize_t length, + ssize_t *wrote) { CURLcode result=CURLE_OK; struct Curl_chunker *ch = &conn->proto.http->chunk; diff --git a/lib/http_chunks.h b/lib/http_chunks.h index 26b79de4e..58a3f12a8 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -81,8 +81,8 @@ struct Curl_chunker { char hexbuffer[ MAXNUM_SIZE + 1]; int hexindex; ChunkyState state; - size_t datasize; - size_t dataleft; /* untouched data amount at the end of the last buffer */ + ssize_t datasize; + ssize_t dataleft; /* untouched data amount at the end of the last buffer */ }; #endif diff --git a/lib/if2ip.c b/lib/if2ip.c index 627422b94..84785a580 100644 --- a/lib/if2ip.c +++ b/lib/if2ip.c @@ -72,6 +72,8 @@ #include #endif +#include "if2ip.h" + /* The last #include file should be: */ #ifdef CURLDEBUG #include "memdebug.h" diff --git a/lib/inet_pton.c b/lib/inet_pton.c index 568f56506..1cd3f80f4 100644 --- a/lib/inet_pton.c +++ b/lib/inet_pton.c @@ -38,6 +38,8 @@ #include #include +#include "inet_pton.h" + #define IN6ADDRSZ 16 #define INADDRSZ 4 #define INT16SZ 2 @@ -68,10 +70,7 @@ static int inet_pton6(const char *src, unsigned char *dst); * Paul Vixie, 1996. */ int -Curl_inet_pton(af, src, dst) - int af; - const char *src; - void *dst; +Curl_inet_pton(int af, const char *src, void *dst) { switch (af) { case AF_INET: @@ -101,9 +100,7 @@ Curl_inet_pton(af, src, dst) * Paul Vixie, 1996. */ static int -inet_pton4(src, dst) - const char *src; - unsigned char *dst; +inet_pton4(const char *src, unsigned char *dst) { static const char digits[] = "0123456789"; int saw_digit, octets, ch; @@ -156,9 +153,7 @@ inet_pton4(src, dst) * Paul Vixie, 1996. */ static int -inet_pton6(src, dst) - const char *src; - unsigned char *dst; +inet_pton6(const char *src, unsigned char *dst) { static const char xdigits_l[] = "0123456789abcdef", xdigits_u[] = "0123456789ABCDEF"; diff --git a/lib/ldap.c b/lib/ldap.c index 5c6778c3a..b08d5fbf7 100644 --- a/lib/ldap.c +++ b/lib/ldap.c @@ -49,6 +49,7 @@ #include "sendf.h" #include "escape.h" #include "transfer.h" +#include "ldap.h" #define _MPRINTF_REPLACE /* use our functions only */ #include diff --git a/lib/md5.c b/lib/md5.c index bfc6e0982..ab76dfc5a 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -159,10 +159,10 @@ struct md5_ctx *context; /* context */ unsigned char *input; /* input block */ unsigned int inputLen; /* length of input block */ { - unsigned int i, index, partLen; + unsigned int i, bufindex, partLen; /* Compute number of bytes mod 64 */ - index = (unsigned int)((context->count[0] >> 3) & 0x3F); + bufindex = (unsigned int)((context->count[0] >> 3) & 0x3F); /* Update number of bits */ if ((context->count[0] += ((UINT4)inputLen << 3)) @@ -170,23 +170,23 @@ unsigned int inputLen; /* length of input block */ context->count[1]++; context->count[1] += ((UINT4)inputLen >> 29); - partLen = 64 - index; + partLen = 64 - bufindex; /* Transform as many times as possible. */ if (inputLen >= partLen) { - MD5_memcpy((void *)&context->buffer[index], (void *)input, partLen); + MD5_memcpy((void *)&context->buffer[bufindex], (void *)input, partLen); MD5Transform(context->state, context->buffer); for (i = partLen; i + 63 < inputLen; i += 64) MD5Transform(context->state, &input[i]); - index = 0; + bufindex = 0; } else i = 0; /* Buffer remaining input */ - MD5_memcpy((void *)&context->buffer[index], (void *)&input[i], + MD5_memcpy((void *)&context->buffer[bufindex], (void *)&input[i], inputLen-i); } @@ -198,14 +198,14 @@ unsigned char digest[16]; /* message digest */ struct md5_ctx *context; /* context */ { unsigned char bits[8]; - unsigned int index, padLen; + unsigned int count, padLen; /* Save number of bits */ Encode (bits, context->count, 8); /* Pad out to 56 mod 64. */ - index = (unsigned int)((context->count[0] >> 3) & 0x3f); - padLen = (index < 56) ? (56 - index) : (120 - index); + count = (unsigned int)((context->count[0] >> 3) & 0x3f); + padLen = (count < 56) ? (56 - count) : (120 - count); MD5_Update (context, PADDING, padLen); /* Append length (before padding) */ @@ -345,6 +345,7 @@ static void Decode (UINT4 *output, #include #endif +#include "md5.h" void Curl_md5it(unsigned char *outbuffer, /* 16 bytes */ unsigned char *input) diff --git a/lib/memdebug.c b/lib/memdebug.c index 7bb3fea34..aea6f324b 100644 --- a/lib/memdebug.c +++ b/lib/memdebug.c @@ -41,7 +41,8 @@ #include #endif -/* DONT include memdebug.h here! */ +#define MEMDEBUG_NODEFINES /* don't redefine the standard functions */ +#include "memdebug.h" struct memdebug { int size; @@ -194,7 +195,8 @@ void curl_dofree(void *ptr, int line, const char *source) fprintf(logfile, "MEM %s:%d free(%p)\n", source, line, ptr); } -int curl_socket(int domain, int type, int protocol, int line, char *source) +int curl_socket(int domain, int type, int protocol, int line, + const char *source) { int sockfd=(socket)(domain, type, protocol); if(logfile && (sockfd!=-1)) @@ -214,7 +216,7 @@ int curl_accept(int s, struct sockaddr *addr, socklen_t *addrlen, } /* this is our own defined way to close sockets on *ALL* platforms */ -int curl_sclose(int sockfd, int line, char *source) +int curl_sclose(int sockfd, int line, const char *source) { int res=sclose(sockfd); if(logfile) diff --git a/lib/memdebug.h b/lib/memdebug.h index f1454b63b..6c289bd4d 100644 --- a/lib/memdebug.h +++ b/lib/memdebug.h @@ -49,7 +49,7 @@ void curl_memdebug(const char *logname); void curl_memlimit(long limit); /* file descriptor manipulators */ -int curl_socket(int domain, int type, int protocol, int, const char *); +int curl_socket(int domain, int type, int protocol, int line , const char *); int curl_sclose(int sockfd, int, const char *source); int curl_accept(int s, struct sockaddr *addr, socklen_t *addrlen, int line, const char *source); @@ -59,6 +59,8 @@ FILE *curl_fopen(const char *file, const char *mode, int line, const char *source); int curl_fclose(FILE *file, int line, const char *source); +#ifndef MEMDEBUG_NODEFINES + /* Set this symbol on the command-line, recompile all lib-sources */ #undef strdup #define strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__) @@ -84,4 +86,6 @@ int curl_fclose(FILE *file, int line, const char *source); #define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__) #define fclose(file) curl_fclose(file,__LINE__,__FILE__) +#endif /* MEMDEBUG_NODEFINES */ + #endif diff --git a/lib/mprintf.c b/lib/mprintf.c index a323bf554..42199cb8f 100644 --- a/lib/mprintf.c +++ b/lib/mprintf.c @@ -40,6 +40,8 @@ #include /* for the curl_off_t type */ +#include + #ifndef SIZEOF_LONG_DOUBLE #define SIZEOF_LONG_DOUBLE 0 #endif diff --git a/lib/netrc.c b/lib/netrc.c index a98520ce6..059ccdabc 100644 --- a/lib/netrc.c +++ b/lib/netrc.c @@ -41,6 +41,7 @@ #endif #include +#include "netrc.h" #include "strequal.h" #include "strtok.h" diff --git a/lib/progress.c b/lib/progress.c index b22f4a70b..467b585c2 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -333,13 +333,15 @@ int Curl_pgrsUpdate(struct connectdata *conn) } /* Figure out the estimated time of arrival for the upload */ - if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && data->progress.ulspeed){ + if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && + (data->progress.ulspeed > 0)) { ulestimate = data->progress.size_ul / data->progress.ulspeed; ulpercen = (data->progress.uploaded / data->progress.size_ul)*100; } /* ... and the download */ - if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && data->progress.dlspeed) { + if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && + (data->progress.dlspeed > 0)) { dlestimate = data->progress.size_dl / data->progress.dlspeed; dlpercen = (data->progress.downloaded / data->progress.size_dl)*100; } @@ -351,7 +353,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* If we have a total estimate, we can display that and the expected time left */ - if(total_estimate) { + if(total_estimate > 0) { time2str(time_left, (int)(total_estimate - data->progress.timespent)); time2str(time_total, (int)total_estimate); } @@ -374,7 +376,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) total_transfer = data->progress.downloaded + data->progress.uploaded; /* Get the percentage of data transfered so far */ - if(total_expected_transfer) + if(total_expected_transfer > 0) total_percen=(double)(total_transfer/total_expected_transfer)*100; fprintf(data->set.err, diff --git a/lib/sendf.c b/lib/sendf.c index 13275913e..fe3cbb422 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -189,7 +189,7 @@ CURLcode Curl_sendf(int sockfd, struct connectdata *conn, write_len = strlen(s); sptr = s; - do { + while (1) { /* Write the buffer to the socket */ res = Curl_write(conn, sockfd, sptr, write_len, &bytes_written); @@ -207,8 +207,7 @@ CURLcode Curl_sendf(int sockfd, struct connectdata *conn, } else break; - - } while(1); + } free(s); /* free the output string */ diff --git a/lib/share.c b/lib/share.c index f077e834e..d6cb7cfdc 100644 --- a/lib/share.c +++ b/lib/share.c @@ -178,7 +178,7 @@ curl_share_cleanup(CURLSH *sh) CURLSHcode Curl_share_lock(struct SessionHandle *data, curl_lock_data type, - curl_lock_access access) + curl_lock_access accesstype) { struct Curl_share *share = data->share; @@ -186,7 +186,7 @@ Curl_share_lock(struct SessionHandle *data, curl_lock_data type, return CURLSHE_INVALID; if(share->specifier & (1<lockfunc(data, type, access, share->clientdata); + share->lockfunc(data, type, accesstype, share->clientdata); } /* else if we don't share this, pretend successful lock */ diff --git a/lib/ssluse.c b/lib/ssluse.c index f53c8dc7e..48c7c8e03 100644 --- a/lib/ssluse.c +++ b/lib/ssluse.c @@ -43,6 +43,7 @@ #include "formdata.h" /* for the boundary function */ #include "url.h" /* for the ssl config check function */ #include "inet_pton.h" +#include "ssluse.h" #ifdef USE_SSLEAY #include @@ -1057,7 +1058,7 @@ Curl_SSLConnect(struct connectdata *conn, /* pass the raw socket into the SSL layers */ SSL_set_fd(connssl->handle, sockfd); - do { + while(1) { fd_set writefd; fd_set readfd; struct timeval interval; @@ -1167,7 +1168,7 @@ Curl_SSLConnect(struct connectdata *conn, } else break; /* get out of loop */ - } while(1); + } /* loop */ /* Informational message */ infof (data, "SSL connection using %s\n", diff --git a/lib/strequal.c b/lib/strequal.c index 4349b500a..37a68876e 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -26,6 +26,8 @@ #include #include +#include "strequal.h" + #ifdef HAVE_STRCASECMP /* this is for "-ansi -Wall -pedantic" to stop complaining! */ extern int (strcasecmp)(const char *s1, const char *s2); diff --git a/lib/strtok.c b/lib/strtok.c index 33927ee8d..630e4e029 100644 --- a/lib/strtok.c +++ b/lib/strtok.c @@ -27,6 +27,8 @@ #include #include +#include "strtok.h" + char * Curl_strtok_r(char *ptr, const char *sep, char **end) { diff --git a/lib/telnet.c b/lib/telnet.c index fc50414cd..eb96cad08 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -72,6 +72,7 @@ #include #include "transfer.h" #include "sendf.h" +#include "telnet.h" #define _MPRINTF_REPLACE /* use our functions only */ #include