From c401ccdcaa72b44f2ae52bd0771ed92a8d0ea556 Mon Sep 17 00:00:00 2001 From: Lammert Bies Date: Mon, 26 Dec 2016 00:35:58 +0100 Subject: [PATCH] Fixed issued with good old gcc 4.4.7 --- src/extern_sha1.c | 2 +- src/httplib_config_options.c | 6 +++++- src/httplib_get_builtin_mime_type.c | 20 ++++++++++---------- src/httplib_handle_cgi_request.c | 16 +++++++++++----- src/httplib_handle_request.c | 15 +++++++++++---- src/httplib_main.h | 25 ++++++++++++++++++------- src/httplib_process_new_connection.c | 7 ++++++- src/httplib_read_auth_file.c | 9 ++++++--- src/httplib_send_file_data.c | 1 + src/httplib_ssl.h | 2 +- src/httplib_ssl_get_client_cert_info.c | 2 +- src/httplib_websocket_client_write.c | 4 ++-- src/httplib_worker_thread.c | 14 +++++++++----- test/testmime.c | 12 ++++++------ 14 files changed, 88 insertions(+), 47 deletions(-) diff --git a/src/extern_sha1.c b/src/extern_sha1.c index f85260ef..c8bc2ee3 100644 --- a/src/extern_sha1.c +++ b/src/extern_sha1.c @@ -47,7 +47,7 @@ static int is_big_endian(void) { static const int n = 1; - return ((char *)&n)[0] == 0; + return ((const char *)&n)[0] == 0; } diff --git a/src/httplib_config_options.c b/src/httplib_config_options.c index 83b44353..6afcbe72 100644 --- a/src/httplib_config_options.c +++ b/src/httplib_config_options.c @@ -88,4 +88,8 @@ struct httplib_option XX_httplib_config_options[] = { * compatible sizes */ -httplib_static_assert((sizeof(XX_httplib_config_options) / sizeof(XX_httplib_config_options[0])) == (NUM_OPTIONS + 1), "XX_httplib_config_options and enum not sync"); +/* + * TODO: LJB: Move to test functions + */ + +// httplib_static_assert((sizeof(XX_httplib_config_options) / sizeof(XX_httplib_config_options[0])) == (NUM_OPTIONS + 1), "XX_httplib_config_options and enum not sync"); diff --git a/src/httplib_get_builtin_mime_type.c b/src/httplib_get_builtin_mime_type.c index 205ae56a..d9bd26fa 100644 --- a/src/httplib_get_builtin_mime_type.c +++ b/src/httplib_get_builtin_mime_type.c @@ -589,7 +589,7 @@ const char *httplib_get_builtin_mime_type( const char *path ) { /* - * const char *XX_httplib_builtin_mime_ext( int index ); + * const char *XX_httplib_builtin_mime_ext( int idx ); * * The function XX_httplib_builtin_mime_ext() returns the file extension of * a MIME type as stored in a specific location in the list with MIME types. @@ -597,19 +597,19 @@ const char *httplib_get_builtin_mime_type( const char *path ) { * If the index is invalid, NULL is returned. */ -const char *XX_httplib_builtin_mime_ext( int index ) { +const char *XX_httplib_builtin_mime_ext( int idx ) { - if ( index < 0 ) return NULL; - if ( index >= NUM_MIME_TYPES ) return NULL; + if ( idx < 0 ) return NULL; + if ( idx >= NUM_MIME_TYPES ) return NULL; - return builtin_mime_types[index].extension; + return builtin_mime_types[idx].extension; } /* XX_httplib_builtin_mime_ext */ /* - * const char *XX_httplib_builtin_mime_type( int index ); + * const char *XX_httplib_builtin_mime_type( int idx ); * * The function XX_httplib_builtin_mime_type() returns the MIME type of of a * record stored in a specific location in the list with MIME types. @@ -617,11 +617,11 @@ const char *XX_httplib_builtin_mime_ext( int index ) { * If the index is invalid, NULL is returned. */ -const char *XX_httplib_builtin_mime_type( int index ) { +const char *XX_httplib_builtin_mime_type( int idx ) { - if ( index < 0 ) return NULL; - if ( index >= NUM_MIME_TYPES ) return NULL; + if ( idx < 0 ) return NULL; + if ( idx >= NUM_MIME_TYPES ) return NULL; - return builtin_mime_types[index].mime_type; + return builtin_mime_types[idx].mime_type; } /* XX_httplib_builtin_mime_type */ diff --git a/src/httplib_handle_cgi_request.c b/src/httplib_handle_cgi_request.c index 0827e345..4f799e0c 100644 --- a/src/httplib_handle_cgi_request.c +++ b/src/httplib_handle_cgi_request.c @@ -54,7 +54,8 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char const char *connection_state; char *pbuf; char dir[PATH_MAX]; - char *p; + char *ptr; + const char *cptr; struct httplib_request_info ri; struct cgi_environment blk; FILE *in; @@ -90,11 +91,16 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char goto done; } - if ( (p = strrchr(dir, '/')) != NULL ) *p++ = '\0'; + if ( (ptr = strrchr(dir, '/')) != NULL ) { + + *ptr++ = '\0'; + cptr = ptr; + } else { - dir[0] = '.', dir[1] = '\0'; - p = (char *)prog; + dir[0] = '.'; + dir[1] = '\0'; + cptr = prog; } if ( pipe(fdin) != 0 || pipe(fdout) != 0 || pipe(fderr) != 0 ) { @@ -106,7 +112,7 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char goto done; } - pid = XX_httplib_spawn_process( conn, p, blk.buf, blk.var, fdin, fdout, fderr, dir ); + pid = XX_httplib_spawn_process( conn, cptr, blk.buf, blk.var, fdin, fdout, fderr, dir ); if ( pid == (pid_t)-1 ) { diff --git a/src/httplib_handle_request.c b/src/httplib_handle_request.c index 4e7b87c6..388bf97b 100644 --- a/src/httplib_handle_request.c +++ b/src/httplib_handle_request.c @@ -59,6 +59,10 @@ void XX_httplib_handle_request( struct httplib_connection *conn ) { void *callback_data; httplib_authorization_handler auth_handler; void *auth_callback_data; + union { + const char * con; + char * var; + } ptr; #if !defined(NO_FILES) time_t curtime = time( NULL ); char date[64]; @@ -92,8 +96,9 @@ void XX_httplib_handle_request( struct httplib_connection *conn ) { * 1.1. split into url and query string */ - conn->request_info.query_string = strchr( ri->request_uri, '?' ); - if ( conn->request_info.query_string != NULL ) *((char *)conn->request_info.query_string++) = '\0'; + ptr.var = strchr( ri->request_uri, '?' ); + if ( ptr.var != NULL ) *(ptr.var++) = '\0'; + conn->request_info.query_string = ptr.var; /* * 1.2. do a https redirect, if required. Do not decode URIs yet. @@ -124,14 +129,16 @@ void XX_httplib_handle_request( struct httplib_connection *conn ) { * 1.3. decode url (if config says so) */ - if ( XX_httplib_should_decode_url( conn ) ) httplib_url_decode( ri->local_uri, uri_len, (char *)ri->local_uri, uri_len + 1, 0 ); + ptr.con = ri->local_uri; + if ( XX_httplib_should_decode_url( conn ) ) httplib_url_decode( ptr.con, uri_len, ptr.var, uri_len + 1, 0 ); /* * 1.4. clean URIs, so a path like allowed_dir/../forbidden_file is * not possible */ - XX_httplib_remove_double_dots_and_double_slashes( (char *)ri->local_uri ); + ptr.con = ri->local_uri; + XX_httplib_remove_double_dots_and_double_slashes( ptr.var ); /* * step 1. completed, the url is known now diff --git a/src/httplib_main.h b/src/httplib_main.h index 06517059..2db4c60d 100644 --- a/src/httplib_main.h +++ b/src/httplib_main.h @@ -98,9 +98,14 @@ char static_assert_replacement[1]; #define httplib_static_assert(cond, txt) extern char static_assert_replacement[(cond) ? 1 : -1] #endif /* _MSC_VER && _MSC_VER >= 1600 */ -httplib_static_assert(sizeof(int) == 4 || sizeof(int) == 8, "int data type size check"); -httplib_static_assert(sizeof(void *) == 4 || sizeof(void *) == 8, "pointer data type size check"); -httplib_static_assert(sizeof(void *) >= sizeof(int), "data type size check"); +/* + * TODO: LJB: Following asserts should not be in this section but in the test routines + * because older GCC versions (4.4.7) throw errors on this + */ + +// httplib_static_assert(sizeof(int) == 4 || sizeof(int) == 8, "int data type size check"); +// httplib_static_assert(sizeof(void *) == 4 || sizeof(void *) == 8, "pointer data type size check"); +// httplib_static_assert(sizeof(void *) >= sizeof(int), "data type size check"); /* DTL -- including winsock2.h works better if lean and mean */ @@ -505,7 +510,11 @@ extern CRITICAL_SECTION global_log_file_lock; #define MAX_CGI_ENVIR_VARS (256) #define MG_BUF_LEN (8192) -httplib_static_assert(MAX_REQUEST_SIZE >= 256, "request size length must be a positive number"); +/* + * TODO: LJB: Move to test functions + */ + +// httplib_static_assert(MAX_REQUEST_SIZE >= 256, "request size length must be a positive number"); /* Describes listening socket, or socket which was accept()-ed by the master @@ -742,10 +751,12 @@ typedef struct { unsigned char buffer[64]; } SHA1_CTX; +/* + * TODO: LJB: Move to test functions + */ - -httplib_static_assert(MAX_WORKER_THREADS >= 1, "worker threads must be a positive number"); -httplib_static_assert(sizeof(size_t) == 4 || sizeof(size_t) == 8, "size_t data type size check"); +// httplib_static_assert(MAX_WORKER_THREADS >= 1, "worker threads must be a positive number"); +// httplib_static_assert(sizeof(size_t) == 4 || sizeof(size_t) == 8, "size_t data type size check"); /* va_copy should always be a macro, C99 and C++11 - DTL */ #ifndef va_copy diff --git a/src/httplib_process_new_connection.c b/src/httplib_process_new_connection.c index 6ff0e97e..86cc8f2d 100644 --- a/src/httplib_process_new_connection.c +++ b/src/httplib_process_new_connection.c @@ -46,6 +46,10 @@ void XX_httplib_process_new_connection( struct httplib_connection *conn ) { const char *hostend; int reqerr; int uri_type; + union { + const void * con; + void * var; + } ptr; if ( conn == NULL || conn->ctx == NULL ) return; @@ -150,7 +154,8 @@ void XX_httplib_process_new_connection( struct httplib_connection *conn ) { if ( ri->remote_user != NULL ) { - httplib_free( (void *) ri->remote_user ); + ptr.con = ri->remote_user; + httplib_free( ptr.var ); /* * Important! When having connections with and without auth diff --git a/src/httplib_read_auth_file.c b/src/httplib_read_auth_file.c index 08afd8ab..ee190134 100644 --- a/src/httplib_read_auth_file.c +++ b/src/httplib_read_auth_file.c @@ -37,10 +37,13 @@ bool XX_httplib_read_auth_file( struct file *filep, struct read_auth_file_struct *workdata ) { - char *p; int is_authorized; struct file fp; size_t l; + union { + const char * con; + char * var; + } ptr; if ( filep == NULL || workdata == NULL ) return false; @@ -50,9 +53,9 @@ bool XX_httplib_read_auth_file( struct file *filep, struct read_auth_file_struct * Loop over passwords file */ - p = (char *)filep->membuf; + ptr.con = filep->membuf; - while ( XX_httplib_fgets( workdata->buf, sizeof(workdata->buf), filep, &p ) != NULL ) { + while ( XX_httplib_fgets( workdata->buf, sizeof(workdata->buf), filep, &ptr.var ) != NULL ) { l = strlen( workdata->buf ); diff --git a/src/httplib_send_file_data.c b/src/httplib_send_file_data.c index 14b8d037..b9447a54 100644 --- a/src/httplib_send_file_data.c +++ b/src/httplib_send_file_data.c @@ -25,6 +25,7 @@ * Release: 2.0 */ +#include #include "httplib_main.h" /* diff --git a/src/httplib_ssl.h b/src/httplib_ssl.h index 34b2c9bf..d1e85372 100644 --- a/src/httplib_ssl.h +++ b/src/httplib_ssl.h @@ -125,7 +125,7 @@ struct ssl_func { #define X509_get_serialNumber (*(ASN1_INTEGER * (*)(X509 *))XX_httplib_crypto_sw[15].ptr) #define i2c_ASN1_INTEGER (*(int (*)(ASN1_INTEGER *, unsigned char **))XX_httplib_crypto_sw[16].ptr) #define EVP_get_digestbyname (*(const EVP_MD *(*)(const char *))XX_httplib_crypto_sw[17].ptr) -#define ASN1_digest (*(int (*)(int (*)(), const EVP_MD *, char *, unsigned char *, unsigned int *))XX_httplib_crypto_sw[18].ptr) +#define ASN1_digest (*(int (*)(int (*)(void), const EVP_MD *, char *, unsigned char *, unsigned int *))XX_httplib_crypto_sw[18].ptr) #define i2d_X509 (*(int (*)(X509 *, unsigned char **))XX_httplib_crypto_sw[19].ptr) #endif /* NO_SSL_DL */ diff --git a/src/httplib_ssl_get_client_cert_info.c b/src/httplib_ssl_get_client_cert_info.c index 522092a3..5b1987c7 100644 --- a/src/httplib_ssl_get_client_cert_info.c +++ b/src/httplib_ssl_get_client_cert_info.c @@ -100,7 +100,7 @@ void XX_httplib_ssl_get_client_cert_info( struct httplib_connection *conn ) { */ ulen = 0; - ASN1_digest( (int (*)())i2d_X509, digest, (char *)cert, buf, &ulen ); + ASN1_digest( (int (*)(void))i2d_X509, digest, (char *)cert, buf, &ulen ); if ( ! hexdump2string( buf, (int)ulen, str_finger, (int)sizeof(str_finger) ) ) *str_finger = 0; diff --git a/src/httplib_websocket_client_write.c b/src/httplib_websocket_client_write.c index 1d4e027a..9ca4708d 100644 --- a/src/httplib_websocket_client_write.c +++ b/src/httplib_websocket_client_write.c @@ -87,7 +87,7 @@ static void mask_data( const char *in, size_t in_len, uint32_t masking_key, char while ( i+3 < in_len ) { - *(uint32_t *)(void *)(out + i) = *(uint32_t *)(void *)(in + i) ^ masking_key; + *(uint32_t *)(void *)(out + i) = *(const uint32_t *)(const void *)(in + i) ^ masking_key; i += 4; } } @@ -99,7 +99,7 @@ static void mask_data( const char *in, size_t in_len, uint32_t masking_key, char while ( i < in_len ) { - *(uint8_t *)(void *)(out + i) = *(uint8_t *)(void *)(in + i) ^ *(((uint8_t *)&masking_key) + (i % 4)); + *(uint8_t *)(void *)(out + i) = *(const uint8_t *)(const void *)(in + i) ^ *(((uint8_t *)&masking_key) + (i % 4)); i++; } } diff --git a/src/httplib_worker_thread.c b/src/httplib_worker_thread.c index 00c9a511..19f58e87 100644 --- a/src/httplib_worker_thread.c +++ b/src/httplib_worker_thread.c @@ -71,6 +71,10 @@ static void *worker_thread_run( struct worker_thread_args *thread_args ) { struct httplib_context *ctx = thread_args->ctx; struct httplib_connection *conn; struct httplib_workerTLS tls; + union { + const void * con; + void * var; + } ptr; if ( thread_args == NULL ) return NULL; @@ -159,11 +163,11 @@ static void *worker_thread_run( struct worker_thread_args *thread_args ) { if ( conn->request_info.client_cert != NULL ) { - httplib_free( (void *)conn->request_info.client_cert->subject ); - httplib_free( (void *)conn->request_info.client_cert->issuer ); - httplib_free( (void *)conn->request_info.client_cert->serial ); - httplib_free( (void *)conn->request_info.client_cert->finger ); - httplib_free( (void *)conn->request_info.client_cert ); + ptr.con = conn->request_info.client_cert->subject; httplib_free( ptr.var ); + ptr.con = conn->request_info.client_cert->issuer; httplib_free( ptr.var ); + ptr.con = conn->request_info.client_cert->serial; httplib_free( ptr.var ); + ptr.con = conn->request_info.client_cert->finger; httplib_free( ptr.var ); + httplib_free( conn->request_info.client_cert ); conn->request_info.client_cert = NULL; } diff --git a/test/testmime.c b/test/testmime.c index db37e38c..9038560d 100644 --- a/test/testmime.c +++ b/test/testmime.c @@ -40,7 +40,7 @@ int main( void ) { int a; - int index; + int idx; int problems; const char *p1; const char *p2; @@ -48,11 +48,11 @@ int main( void ) { problems = 0; - p1 = XX_httplib_builtin_mime_ext( 0 ); - index = 1; + p1 = XX_httplib_builtin_mime_ext( 0 ); + idx = 1; do { - p2 = XX_httplib_builtin_mime_ext( index ); + p2 = XX_httplib_builtin_mime_ext( idx ); if ( p1 == NULL || p2 == NULL ) break; @@ -62,7 +62,7 @@ int main( void ) { problems++; } - index++; + idx++; p1 = p2; } while ( p1 != NULL && p2 != NULL ); @@ -70,7 +70,7 @@ int main( void ) { printf( "Mime type of CSV: \"%s\"\n", httplib_get_builtin_mime_type( "car.CsV" ) ); - for (a=0; a