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: 2012/05/01:
Cleanup settings of CFLAGS in Makefile Cleanup settings of CFLAGS in Makefile
Fix signed/unsigned integer comparaisons
2012/04/20: 2012/04/20:
Allow to specify protocol with TCP or UDP for -A option 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 /* Project : miniUPnP
* Author : Thomas Bernard * Author : Thomas Bernard
* Copyright (c) 2011 Thomas Bernard * Copyright (c) 2011 Thomas Bernard
@ -190,7 +190,7 @@ void handle_http_connection(int c)
int content_length = 16*1024; int content_length = 16*1024;
/* read the request */ /* read the request */
while(request_len < sizeof(request_buffer) && !headers_found) { while(request_len < (int)sizeof(request_buffer) && !headers_found) {
n = read(c, n = read(c,
request_buffer + request_len, request_buffer + request_len,
sizeof(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); printf("headers :\n%.*s", request_len, request_buffer);
/* the request have been received, now parse the request line */ /* the request have been received, now parse the request line */
p = request_buffer; 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') if(*p == ' ' || *p == '\r')
break; break;
request_method[i] = *p; request_method[i] = *p;
@ -227,7 +227,7 @@ void handle_http_connection(int c)
request_method[i] = '\0'; request_method[i] = '\0';
while(*p == ' ') while(*p == ' ')
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') if(*p == ' ' || *p == '\r')
break; break;
request_uri[i] = *p; request_uri[i] = *p;
@ -236,7 +236,7 @@ void handle_http_connection(int c)
request_uri[i] = '\0'; request_uri[i] = '\0';
while(*p == ' ') while(*p == ' ')
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') if(*p == ' ' || *p == '\r')
break; break;
http_version[i] = *p; 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 /* Project : miniupnp
* Website : http://miniupnp.free.fr/ * Website : http://miniupnp.free.fr/
* Author : Thomas Bernard * Author : Thomas Bernard
@ -69,13 +69,13 @@ getHTTPResponse(int s, int * size)
unsigned int bytestocopy = 0; unsigned int bytestocopy = 0;
/* buffers : */ /* buffers : */
char * header_buf; char * header_buf;
int header_buf_len = 2048; unsigned int header_buf_len = 2048;
int header_buf_used = 0; unsigned int header_buf_used = 0;
char * content_buf; char * content_buf;
int content_buf_len = 2048; unsigned int content_buf_len = 2048;
int content_buf_used = 0; unsigned int content_buf_used = 0;
char chunksize_buf[32]; char chunksize_buf[32];
int chunksize_buf_index; unsigned int chunksize_buf_index;
header_buf = malloc(header_buf_len); header_buf = malloc(header_buf_len);
content_buf = malloc(content_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) /* search for CR LF CR LF (end of headers)
* recognize also LF LF */ * recognize also LF LF */
i = 0; i = 0;
while(i < (header_buf_used-1) && (endofheaders == 0)) { while(i < ((int)header_buf_used-1) && (endofheaders == 0)) {
if(header_buf[i] == '\r') { if(header_buf[i] == '\r') {
i++; i++;
if(header_buf[i] == '\n') { if(header_buf[i] == '\n') {
i++; i++;
if(i < header_buf_used && header_buf[i] == '\r') { if(i < (int)header_buf_used && header_buf[i] == '\r') {
i++; i++;
if(i < header_buf_used && header_buf[i] == '\n') { if(i < (int)header_buf_used && header_buf[i] == '\n') {
endofheaders = i+1; endofheaders = i+1;
} }
} }
@ -196,7 +196,7 @@ getHTTPResponse(int s, int * size)
i++; /* discarding chunk-extension */ i++; /* discarding chunk-extension */
if(i<n && buf[i] == '\r') i++; if(i<n && buf[i] == '\r') i++;
if(i<n && buf[i] == '\n') { if(i<n && buf[i] == '\n') {
int j; unsigned int j;
for(j = 0; j < chunksize_buf_index; j++) { for(j = 0; j < chunksize_buf_index; j++) {
if(chunksize_buf[j] >= '0' if(chunksize_buf[j] >= '0'
&& chunksize_buf[j] <= '9') && chunksize_buf[j] <= '9')
@ -223,13 +223,13 @@ getHTTPResponse(int s, int * size)
goto end_of_stream; goto end_of_stream;
} }
} }
bytestocopy = ((int)chunksize < n - i)?chunksize:(n - i); bytestocopy = ((int)chunksize < (n - i))?chunksize:(unsigned int)(n - i);
if((int)(content_buf_used + bytestocopy) > content_buf_len) 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; content_buf_len = content_length;
} else { } 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 = (char *)realloc((void *)content_buf,
content_buf_len); content_buf_len);
@ -244,13 +244,13 @@ getHTTPResponse(int s, int * size)
{ {
/* not chunked */ /* not chunked */
if(content_length > 0 if(content_length > 0
&& (content_buf_used + n) > content_length) { && (int)(content_buf_used + n) > content_length) {
/* skipping additional bytes */ /* skipping additional bytes */
n = content_length - content_buf_used; n = content_length - content_buf_used;
} }
if(content_buf_used + n > content_buf_len) 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; content_buf_len = content_length;
} else { } else {
content_buf_len = content_buf_used + n; content_buf_len = content_buf_used + n;
@ -263,7 +263,7 @@ getHTTPResponse(int s, int * size)
} }
} }
/* use the Content-Length header value if available */ /* 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 #ifdef DEBUG
printf("End of HTTP content\n"); printf("End of HTTP content\n");