Fix signed/unsigned integer comparaisons

This commit is contained in:
Thomas Bernard 2012-05-01 20:53:19 +02:00
parent 2c2596c72a
commit 9fc7b7058a
3 changed files with 23 additions and 22 deletions

View File

@ -3,6 +3,7 @@ miniUPnP client Changelog.
2012/05/01:
Cleanup settings of CFLAGS in Makefile
Fix signed/unsigned integer comparaisons
2012/04/20:
Allow to specify protocol with TCP or UDP for -A option

View File

@ -1,4 +1,4 @@
/* $Id: minihttptestserver.c,v 1.8 2012/04/06 13:53:52 nanard Exp $ */
/* $Id: minihttptestserver.c,v 1.10 2012/05/01 16:24:36 nanard Exp $ */
/* Project : miniUPnP
* Author : Thomas Bernard
* Copyright (c) 2011 Thomas Bernard
@ -190,7 +190,7 @@ void handle_http_connection(int c)
int content_length = 16*1024;
/* read the request */
while(request_len < sizeof(request_buffer) && !headers_found) {
while(request_len < (int)sizeof(request_buffer) && !headers_found) {
n = read(c,
request_buffer + request_len,
sizeof(request_buffer) - request_len);
@ -218,7 +218,7 @@ void handle_http_connection(int c)
printf("headers :\n%.*s", request_len, request_buffer);
/* the request have been received, now parse the request line */
p = request_buffer;
for(i = 0; i < sizeof(request_method) - 1; i++) {
for(i = 0; i < (int)sizeof(request_method) - 1; i++) {
if(*p == ' ' || *p == '\r')
break;
request_method[i] = *p;
@ -227,7 +227,7 @@ void handle_http_connection(int c)
request_method[i] = '\0';
while(*p == ' ')
p++;
for(i = 0; i < sizeof(request_uri) - 1; i++) {
for(i = 0; i < (int)sizeof(request_uri) - 1; i++) {
if(*p == ' ' || *p == '\r')
break;
request_uri[i] = *p;
@ -236,7 +236,7 @@ void handle_http_connection(int c)
request_uri[i] = '\0';
while(*p == ' ')
p++;
for(i = 0; i < sizeof(http_version) - 1; i++) {
for(i = 0; i < (int)sizeof(http_version) - 1; i++) {
if(*p == ' ' || *p == '\r')
break;
http_version[i] = *p;

View File

@ -1,4 +1,4 @@
/* $Id: miniwget.c,v 1.54 2012/01/21 13:30:32 nanard Exp $ */
/* $Id: miniwget.c,v 1.56 2012/05/01 16:16:08 nanard Exp $ */
/* Project : miniupnp
* Website : http://miniupnp.free.fr/
* Author : Thomas Bernard
@ -69,13 +69,13 @@ getHTTPResponse(int s, int * size)
unsigned int bytestocopy = 0;
/* buffers : */
char * header_buf;
int header_buf_len = 2048;
int header_buf_used = 0;
unsigned int header_buf_len = 2048;
unsigned int header_buf_used = 0;
char * content_buf;
int content_buf_len = 2048;
int content_buf_used = 0;
unsigned int content_buf_len = 2048;
unsigned int content_buf_used = 0;
char chunksize_buf[32];
int chunksize_buf_index;
unsigned int chunksize_buf_index;
header_buf = malloc(header_buf_len);
content_buf = malloc(content_buf_len);
@ -99,14 +99,14 @@ getHTTPResponse(int s, int * size)
/* search for CR LF CR LF (end of headers)
* recognize also LF LF */
i = 0;
while(i < (header_buf_used-1) && (endofheaders == 0)) {
while(i < ((int)header_buf_used-1) && (endofheaders == 0)) {
if(header_buf[i] == '\r') {
i++;
if(header_buf[i] == '\n') {
i++;
if(i < header_buf_used && header_buf[i] == '\r') {
if(i < (int)header_buf_used && header_buf[i] == '\r') {
i++;
if(i < header_buf_used && header_buf[i] == '\n') {
if(i < (int)header_buf_used && header_buf[i] == '\n') {
endofheaders = i+1;
}
}
@ -196,7 +196,7 @@ getHTTPResponse(int s, int * size)
i++; /* discarding chunk-extension */
if(i<n && buf[i] == '\r') i++;
if(i<n && buf[i] == '\n') {
int j;
unsigned int j;
for(j = 0; j < chunksize_buf_index; j++) {
if(chunksize_buf[j] >= '0'
&& chunksize_buf[j] <= '9')
@ -223,13 +223,13 @@ getHTTPResponse(int s, int * size)
goto end_of_stream;
}
}
bytestocopy = ((int)chunksize < n - i)?chunksize:(n - i);
if((int)(content_buf_used + bytestocopy) > content_buf_len)
bytestocopy = ((int)chunksize < (n - i))?chunksize:(unsigned int)(n - i);
if((content_buf_used + bytestocopy) > content_buf_len)
{
if(content_length >= content_buf_used + (int)bytestocopy) {
if(content_length >= (int)(content_buf_used + bytestocopy)) {
content_buf_len = content_length;
} else {
content_buf_len = content_buf_used + (int)bytestocopy;
content_buf_len = content_buf_used + bytestocopy;
}
content_buf = (char *)realloc((void *)content_buf,
content_buf_len);
@ -244,13 +244,13 @@ getHTTPResponse(int s, int * size)
{
/* not chunked */
if(content_length > 0
&& (content_buf_used + n) > content_length) {
&& (int)(content_buf_used + n) > content_length) {
/* skipping additional bytes */
n = content_length - content_buf_used;
}
if(content_buf_used + n > content_buf_len)
{
if(content_length >= content_buf_used + n) {
if(content_length >= (int)(content_buf_used + n)) {
content_buf_len = content_length;
} else {
content_buf_len = content_buf_used + n;
@ -263,7 +263,7 @@ getHTTPResponse(int s, int * size)
}
}
/* use the Content-Length header value if available */
if(content_length > 0 && content_buf_used >= content_length)
if(content_length > 0 && (int)content_buf_used >= content_length)
{
#ifdef DEBUG
printf("End of HTTP content\n");