diff --git a/ChangeLog b/ChangeLog index a30cd32..4a0129f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -318,6 +318,13 @@ Version 1.8.0 Version 1.6.16 ******************************************************************************* +2012-03-10 Fabrice Fontaine + + Remove some of the implicit cast in upnp part + + Remove some of the "implicit integer or enum conversions" as well as + some access to NULL reference in upnp part. + 2012-03-10 Fabrice Fontaine Remove lock in ThreadPoolInit diff --git a/upnp/inc/upnp.h b/upnp/inc/upnp.h index 858b5ec..6c0744a 100644 --- a/upnp/inc/upnp.h +++ b/upnp/inc/upnp.h @@ -5,7 +5,7 @@ * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. - * Copyright (C) 2011 France Telecom All rights reserved. + * Copyright (C) 2011-2012 France Telecom All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -65,8 +65,8 @@ #include #endif -#define LINE_SIZE 180 -#define NAME_SIZE 256 +#define LINE_SIZE (size_t)180 +#define NAME_SIZE (size_t)256 #define MNFT_NAME_SIZE 64 #define MODL_NAME_SIZE 32 #define SERL_NUMR_SIZE 64 diff --git a/upnp/src/api/upnpapi.c b/upnp/src/api/upnpapi.c index f3c1fe9..e16e94e 100644 --- a/upnp/src/api/upnpapi.c +++ b/upnp/src/api/upnpapi.c @@ -394,7 +394,9 @@ static int UpnpInitStartServers( /*! [in] Local Port to listen for incoming connections. */ unsigned short DestPort) { +#if EXCLUDE_MINISERVER == 0 || EXCLUDE_WEB_SERVER == 0 int retVal = 0; +#endif UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Entering UpnpInitStartServers\n" ); @@ -1291,9 +1293,9 @@ int UpnpUnRegisterRootDeviceLowPower(UpnpDevice_Handle Hnd, int PowerState, HandleUnlock(); #if EXCLUDE_SSDP == 0 - retVal = AdvertiseAndReply(-1, Hnd, 0, (struct sockaddr *)NULL, - (char *)NULL, (char *)NULL, (char *)NULL, - HInfo->MaxAge); + retVal = AdvertiseAndReply(-1, Hnd, (enum SsdpSearchType)0, + (struct sockaddr *)NULL, (char *)NULL, (char *)NULL, + (char *)NULL, HInfo->MaxAge); #endif HandleLock(); @@ -1690,9 +1692,9 @@ int UpnpSendAdvertisementLowPower(UpnpDevice_Handle Hnd, int Exp, SInfo->SleepPeriod = SleepPeriod; SInfo->RegistrationState = RegistrationState; HandleUnlock(); - retVal = AdvertiseAndReply( 1, Hnd, 0, ( struct sockaddr * )NULL, - ( char * )NULL, ( char * )NULL, - ( char * )NULL, Exp ); + retVal = AdvertiseAndReply( 1, Hnd, ( enum SsdpSearchType )0, + ( struct sockaddr * )NULL, ( char * )NULL, + ( char * )NULL, ( char * )NULL, Exp ); if( retVal != UPNP_E_SUCCESS ) return retVal; @@ -3703,13 +3705,13 @@ Upnp_Handle_Type GetClientHandleInfo( Upnp_Handle_Type GetDeviceHandleInfo( - const int AddressFamily, + const unsigned short AddressFamily, UpnpDevice_Handle *device_handle_out, struct Handle_Info **HndInfo) { /* Check if we've got a registered device of the address family specified. */ - if ((AddressFamily == AF_INET && UpnpSdkDeviceRegisteredV4 == 0) || - (AddressFamily == AF_INET6 && UpnpSdkDeviceregisteredV6 == 0)) { + if ((AddressFamily == (unsigned short)AF_INET && UpnpSdkDeviceRegisteredV4 == 0) || + (AddressFamily == (unsigned short)AF_INET6 && UpnpSdkDeviceregisteredV6 == 0)) { *device_handle_out = -1; return HND_INVALID; } @@ -3732,7 +3734,7 @@ Upnp_Handle_Type GetHandleInfo( UpnpClient_Handle Hnd, struct Handle_Info **HndInfo) { - Upnp_Handle_Type ret = UPNP_E_INVALID_HANDLE; + Upnp_Handle_Type ret = HND_INVALID; UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "GetHandleInfo: entering, Handle is %d\n", Hnd); diff --git a/upnp/src/genlib/net/http/httpparser.c b/upnp/src/genlib/net/http/httpparser.c index d71396e..4d725f2 100644 --- a/upnp/src/genlib/net/http/httpparser.c +++ b/upnp/src/genlib/net/http/httpparser.c @@ -522,11 +522,11 @@ http_header_t *httpmsg_find_hdr( * * Description : skips blank lines at the start of a msg. * -* Return : int ; +* Return : parse_status_t ; * * Note : ************************************************************************/ -static UPNP_INLINE int skip_blank_lines(INOUT scanner_t *scanner) +static UPNP_INLINE parse_status_t skip_blank_lines(INOUT scanner_t *scanner) { memptr token; token_type_t tok_type; @@ -535,9 +535,9 @@ static UPNP_INLINE int skip_blank_lines(INOUT scanner_t *scanner) /* skip ws, crlf */ do { status = scanner_get_token(scanner, &token, &tok_type); - } while (status == PARSE_OK && + } while (status == (parse_status_t)PARSE_OK && (tok_type == TT_WHITESPACE || tok_type == TT_CRLF)); - if (status == PARSE_OK) { + if (status == (parse_status_t)PARSE_OK) { /* pushback a non-whitespace token */ scanner->cursor -= token.length; } @@ -560,7 +560,7 @@ static UPNP_INLINE int skip_blank_lines(INOUT scanner_t *scanner) * * Note : ************************************************************************/ -static UPNP_INLINE int skip_lws(INOUT scanner_t *scanner) +static UPNP_INLINE parse_status_t skip_lws(INOUT scanner_t *scanner) { memptr token; token_type_t tok_type; @@ -574,13 +574,14 @@ static UPNP_INLINE int skip_lws(INOUT scanner_t *scanner) /* get CRLF or WS */ status = scanner_get_token( scanner, &token, &tok_type ); - if( status == PARSE_OK ) { + if( status == ( parse_status_t ) PARSE_OK ) { if( tok_type == TT_CRLF ) { /* get WS */ status = scanner_get_token( scanner, &token, &tok_type ); } - if( status == PARSE_OK && tok_type == TT_WHITESPACE ) { + if( status == ( parse_status_t ) PARSE_OK && + tok_type == TT_WHITESPACE ) { matched = TRUE; } else { /* did not match LWS; pushback token(s) */ @@ -590,7 +591,8 @@ static UPNP_INLINE int skip_lws(INOUT scanner_t *scanner) } while( matched ); /* if entire msg is loaded, ignore an 'incomplete' warning */ - if( status == PARSE_INCOMPLETE && scanner->entire_msg_loaded ) { + if( status == ( parse_status_t ) PARSE_INCOMPLETE && + scanner->entire_msg_loaded ) { status = PARSE_OK; } @@ -631,7 +633,7 @@ static UPNP_INLINE parse_status_t match_non_ws_string( while( !done ) { status = scanner_get_token( scanner, &token, &tok_type ); - if( status == PARSE_OK && + if( status == ( parse_status_t ) PARSE_OK && tok_type != TT_WHITESPACE && tok_type != TT_CRLF ) { /* append non-ws token */ str->length += token.length; @@ -640,13 +642,13 @@ static UPNP_INLINE parse_status_t match_non_ws_string( } } - if( status == PARSE_OK ) { + if( status == ( parse_status_t ) PARSE_OK ) { /* last token was WS; push it back in */ scanner->cursor -= token.length; } /* tolerate 'incomplete' msg */ - if( status == PARSE_OK || - ( status == PARSE_INCOMPLETE && scanner->entire_msg_loaded ) + if( status == ( parse_status_t ) PARSE_OK || + ( status == ( parse_status_t ) PARSE_INCOMPLETE && scanner->entire_msg_loaded ) ) { if( str->length == 0 ) { /* no strings found */ @@ -701,7 +703,7 @@ static UPNP_INLINE parse_status_t match_raw_value( while( !done ) { status = scanner_get_token( scanner, &token, &tok_type ); - if( status == PARSE_OK ) { + if( status == ( parse_status_t ) PARSE_OK ) { if( !saw_crlf ) { if( tok_type == TT_CRLF ) { /* CRLF could end value */ @@ -733,7 +735,7 @@ static UPNP_INLINE parse_status_t match_raw_value( } } - if( status == PARSE_OK ) { + if( status == ( parse_status_t ) PARSE_OK ) { /* trim whitespace on right side of value */ while( raw_value->length > 0 ) { /* get last char */ @@ -771,7 +773,7 @@ static UPNP_INLINE parse_status_t match_raw_value( * PARSE_FAILURE -- bad input * PARSE_INCOMPLETE ************************************************************************/ -static UPNP_INLINE int match_int( +static UPNP_INLINE parse_status_t match_int( INOUT scanner_t *scanner, IN int base, OUT int *value) @@ -785,7 +787,7 @@ static UPNP_INLINE int match_int( save_pos = scanner->cursor; status = scanner_get_token(scanner, &token, &tok_type); - if (status == PARSE_OK) { + if (status == (parse_status_t)PARSE_OK) { if (tok_type == TT_IDENTIFIER) { errno = 0; num = strtol(token.buf, &end_ptr, base); @@ -801,7 +803,7 @@ static UPNP_INLINE int match_int( status = PARSE_NO_MATCH; } } - if (status != PARSE_OK) { + if (status != (parse_status_t)PARSE_OK) { /* restore scanner position for bad values */ scanner->cursor = save_pos; } @@ -825,7 +827,7 @@ static UPNP_INLINE int match_int( * PARSE_FAILURE * PARSE_INCOMPLETE ************************************************************************/ -static UPNP_INLINE int +static UPNP_INLINE parse_status_t read_until_crlf( INOUT scanner_t * scanner, OUT memptr * str ) { @@ -840,9 +842,9 @@ read_until_crlf( INOUT scanner_t * scanner, /* read until we hit a crlf */ do { status = scanner_get_token( scanner, &token, &tok_type ); - } while( status == PARSE_OK && tok_type != TT_CRLF ); + } while( status == ( parse_status_t ) PARSE_OK && tok_type != TT_CRLF ); - if( status == PARSE_OK ) { + if( status == ( parse_status_t ) PARSE_OK ) { /* pushback crlf in stream */ scanner->cursor -= token.length; @@ -947,7 +949,7 @@ match_char( INOUT scanner_t * scanner, * * Note : ************************************************************************/ -static int vfmatch( +static parse_status_t vfmatch( INOUT scanner_t *scanner, IN const char *fmt, va_list argp) @@ -988,7 +990,8 @@ static int vfmatch( assert( str_ptr != NULL ); status = scanner_get_token( scanner, str_ptr, &tok_type ); - if( status == PARSE_OK && tok_type != TT_IDENTIFIER ) { + if( status == ( parse_status_t ) PARSE_OK && + tok_type != TT_IDENTIFIER ) { /* not an identifier */ status = PARSE_NO_MATCH; } @@ -996,7 +999,8 @@ static int vfmatch( case 'c': /* crlf */ status = scanner_get_token( scanner, &token, &tok_type ); - if( status == PARSE_OK && tok_type != TT_CRLF ) { + if( status == ( parse_status_t ) PARSE_OK && + tok_type != TT_CRLF ) { /* not CRLF token */ status = PARSE_NO_MATCH; } @@ -1046,7 +1050,8 @@ static int vfmatch( str_ptr = ( memptr * ) va_arg( argp, memptr * ); status = scanner_get_token( scanner, str_ptr, &tok_type ); - if( status == PARSE_OK && tok_type != TT_QUOTEDSTRING ) { + if( status == ( parse_status_t ) PARSE_OK && + tok_type != TT_QUOTEDSTRING ) { status = PARSE_NO_MATCH; /* not a quoted string */ } break; @@ -1054,7 +1059,8 @@ static int vfmatch( /* optional whitespace */ status = scanner_get_token( scanner, &token, &tok_type ); - if( status == PARSE_OK && tok_type != TT_WHITESPACE ) { + if( status == ( parse_status_t ) PARSE_OK && + tok_type != TT_WHITESPACE ) { /* restore non-whitespace token */ scanner->cursor -= token.length; } @@ -1124,7 +1130,7 @@ static int vfmatch( * PARSE_NO_MATCH * PARSE_INCOMPLETE ************************************************************************/ -static int match( +static parse_status_t match( INOUT scanner_t *scanner, IN const char *fmt, ...) @@ -1156,13 +1162,13 @@ static int match( * PARSE_NO_MATCH -- failure to match pattern 'fmt' * PARSE_FAILURE -- 'str' is bad input ************************************************************************/ -int +parse_status_t matchstr( IN char *str, IN size_t slen, IN const char *fmt, ... ) { - int ret_code; + parse_status_t ret_code; char save_char; scanner_t scanner; membuffer buf; @@ -1245,7 +1251,7 @@ parser_parse_requestline( INOUT http_parser_t * parser ) assert( parser->position == POS_REQUEST_LINE ); status = skip_blank_lines( &parser->scanner ); - if( status != PARSE_OK ) { + if( status != ( parse_status_t ) PARSE_OK ) { return status; } /*simple get http 0.9 as described in http 1.0 spec */ @@ -1253,7 +1259,7 @@ parser_parse_requestline( INOUT http_parser_t * parser ) status = match( &parser->scanner, "%s\t%S%w%c", &method_str, &url_str ); - if( status == PARSE_OK ) { + if( status == ( parse_status_t ) PARSE_OK ) { index = map_str_to_int( method_str.buf, method_str.length, @@ -1292,7 +1298,7 @@ parser_parse_requestline( INOUT http_parser_t * parser ) status = match( &parser->scanner, "%s\t%S\t%ihttp%w/%w%L%c", &method_str, &url_str, &version_str ); - if( status != PARSE_OK ) { + if( status != ( parse_status_t ) PARSE_OK ) { return status; } /* store url */ @@ -1333,7 +1339,7 @@ parser_parse_requestline( INOUT http_parser_t * parser ) return PARSE_FAILURE; } - hmsg->method = Http_Method_Table[index].id; + hmsg->method = ( http_method_t ) Http_Method_Table[index].id; parser->position = POS_HEADERS; /* move to headers */ return PARSE_OK; @@ -1366,14 +1372,14 @@ parse_status_t parser_parse_responseline(INOUT http_parser_t *parser) assert(parser->position == POS_RESPONSE_LINE); status = skip_blank_lines(&parser->scanner); - if (status != PARSE_OK) + if (status != ( parse_status_t) PARSE_OK) return status; /* response line */ /*status = match( &parser->scanner, "%ihttp%w/%w%d\t.\t%d\t%d\t%L%c", */ /* &hmsg->major_version, &hmsg->minor_version, */ /* &hmsg->status_code, &hmsg->status_msg ); */ status = match(&parser->scanner, "%ihttp%w/%w%L%c", &line); - if (status != PARSE_OK) + if (status != ( parse_status_t ) PARSE_OK) return status; save_char = line.buf[line.length]; line.buf[line.length] = '\0'; /* null-terminate */ diff --git a/upnp/src/genlib/net/http/httpreadwrite.c b/upnp/src/genlib/net/http/httpreadwrite.c index 8c2db66..2b7853d 100644 --- a/upnp/src/genlib/net/http/httpreadwrite.c +++ b/upnp/src/genlib/net/http/httpreadwrite.c @@ -902,7 +902,7 @@ typedef struct HTTPCONNECTIONHANDLE { * \li \c PARSE_FAILURE - Failure to parse data correctly * \li \c UPNP_E_BAD_HTTPMSG - Socker read() returns an error */ -static int ReadResponseLineAndHeaders( +static parse_status_t ReadResponseLineAndHeaders( /*! Socket information object. */ IN SOCKINFO *info, /*! HTTP Parser object. */ @@ -1220,12 +1220,13 @@ int http_GetHttpResponse(void *Handle, UpnpString *headers, status = ReadResponseLineAndHeaders(&handle->sock_info, &handle->response, &timeout, &http_error_code); - if (status != PARSE_OK) { + if (status != (parse_status_t)PARSE_OK) { ret_code = UPNP_E_BAD_RESPONSE; goto errorHandler; } status = parser_get_entity_read_method(&handle->response); - if (status != PARSE_CONTINUE_1 && status != PARSE_SUCCESS) { + if (status != (parse_status_t)PARSE_CONTINUE_1 && + status != (parse_status_t)PARSE_SUCCESS) { ret_code = UPNP_E_BAD_RESPONSE; goto errorHandler; } @@ -1515,6 +1516,8 @@ int http_MakeMessage(membuffer *buf, int http_major_version, } assert(loc_time); date = gmtime(loc_time); + if (date == NULL) + goto error_handler; rc = snprintf(tempbuf, sizeof(tempbuf), "%s%s, %02d %s %d %02d:%02d:%02d GMT%s", start_str, &weekday_str[date->tm_wday * 4], @@ -1875,13 +1878,14 @@ int http_OpenHttpGetEx( } status = ReadResponseLineAndHeaders(&handle->sock_info, &handle->response, &timeout, &http_error_code); - if (status != PARSE_OK) { + if (status != (parse_status_t)PARSE_OK) { errCode = UPNP_E_BAD_RESPONSE; free(handle); break; } status = parser_get_entity_read_method(&handle->response); - if (status != PARSE_CONTINUE_1 && status != PARSE_SUCCESS) { + if (status != (parse_status_t)PARSE_CONTINUE_1 && + status != (parse_status_t)PARSE_SUCCESS) { errCode = UPNP_E_BAD_RESPONSE; free(handle); break; diff --git a/upnp/src/genlib/net/uri/uri.c b/upnp/src/genlib/net/uri/uri.c index 5a0b3a2..89c7a7d 100644 --- a/upnp/src/genlib/net/uri/uri.c +++ b/upnp/src/genlib/net/uri/uri.c @@ -139,14 +139,14 @@ int replace_escaped(char *in, size_t index, size_t *max) size_t i = 0; size_t j = 0; - if (in[index] == '%' && isxdigit(in[index + 1]) && isxdigit(in[index + 2])) { + if (in[index] == '%' && isxdigit(in[index + (size_t)1]) && isxdigit(in[index + (size_t)2])) { /* Note the "%2x", makes sure that we convert a maximum of two * characters. */ - if (sscanf(&in[index + 1], "%2x", &tempInt) != 1) { + if (sscanf(&in[index + (size_t)1], "%2x", &tempInt) != 1) { return 0; } tempChar = (char)tempInt; - for (i = index + 3, j = index; j < *max; i++, j++) { + for (i = index + (size_t)3, j = index; j < *max; i++, j++) { in[j] = tempChar; if (i < *max) { tempChar = in[i]; @@ -154,7 +154,7 @@ int replace_escaped(char *in, size_t index, size_t *max) tempChar = 0; } } - *max -= 2; + *max -= (size_t)2; return 1; } else { return 0; @@ -176,12 +176,12 @@ static size_t parse_uric( /*! [out] Token object where the string of characters is copied. */ token *out) { - size_t i = 0; + size_t i = (size_t)0; while (i < max && (is_unreserved(in[i]) || is_reserved(in[i]) || - ((i + 2 < max) && is_escaped(&in[i])))) { + ((i + (size_t)2 < max) && is_escaped(&in[i])))) { i++; } @@ -414,14 +414,14 @@ int parse_hostport( } /* The length of the host and port string can be calculated by */ /* subtracting pointers. */ - hostport_size = (size_t)(c - workbuf); + hostport_size = (size_t)c - (size_t)workbuf; /* Fill in the 'out' information. */ if (af == AF_INET) { - sai4->sin_family = AF_INET; + sai4->sin_family = (unsigned short)AF_INET; sai4->sin_port = htons(port); ret = inet_pton(AF_INET, srvname, &sai4->sin_addr); } else if (af == AF_INET6) { - sai6->sin6_family = AF_INET6; + sai6->sin6_family = (unsigned short)AF_INET6; sai6->sin6_port = htons(port); sai6->sin6_scope_id = gIF_INDEX; ret = inet_pton(AF_INET6, srvname, &sai6->sin6_addr); @@ -462,19 +462,19 @@ static size_t parse_scheme( /*! [out] Output parameter whose buffer is filled in with the scheme. */ token *out) { - size_t i = 0; + size_t i = (size_t)0; - out->size = 0; + out->size = (size_t)0; out->buff = NULL; - if( ( max == 0 ) || ( !isalpha( in[0] ) ) ) - return 0; + if( ( max == (size_t)0 ) || ( !isalpha( in[0] ) ) ) + return (size_t)0; i++; while( ( i < max ) && ( in[i] != ':' ) ) { if( !( isalnum( in[i] ) || ( in[i] == '+' ) || ( in[i] == '-' ) || ( in[i] == '.' ) ) ) - return 0; + return (size_t)0; i++; } if( i < max ) { @@ -483,15 +483,15 @@ static size_t parse_scheme( return i; } - return 0; + return (size_t)0; } int remove_escaped_chars(INOUT char *in, INOUT size_t *size) { - size_t i = 0; + size_t i = (size_t)0; - for (i = 0; i < *size; i++) { + for (i = (size_t)0; i < *size; i++) { replace_escaped(in, i, size); } @@ -570,7 +570,7 @@ char *resolve_rel_url(char *base_url, char *rel_url) uri_type base; uri_type rel; - size_t i = 0; + size_t i = (size_t)0; char *finger = NULL; char *last_slash = NULL; @@ -579,7 +579,7 @@ char *resolve_rel_url(char *base_url, char *rel_url) if( base_url && rel_url ) { out = - ( char * )malloc( strlen( base_url ) + strlen( rel_url ) + 2 ); + ( char * )malloc( strlen( base_url ) + strlen( rel_url ) + (size_t)2 ); } else { if( rel_url ) return strdup( rel_url ); @@ -590,36 +590,36 @@ char *resolve_rel_url(char *base_url, char *rel_url) if( out == NULL ) { return NULL; } - memset( out, 0, strlen( base_url ) + strlen( rel_url ) + 2 ); + memset( out, 0, strlen( base_url ) + strlen( rel_url ) + (size_t)2 ); if( ( parse_uri( rel_url, strlen( rel_url ), &rel ) ) == HTTP_SUCCESS ) { - if( rel.type == ABSOLUTE ) { + if( rel.type == ( enum uriType) ABSOLUTE ) { strncpy( out, rel_url, strlen ( rel_url ) ); } else { if( ( parse_uri( base_url, strlen( base_url ), &base ) == HTTP_SUCCESS ) - && ( base.type == ABSOLUTE ) ) { + && ( base.type == ( enum uriType ) ABSOLUTE ) ) { - if( strlen( rel_url ) == 0 ) { + if( strlen( rel_url ) == (size_t)0 ) { strncpy( out, base_url, strlen ( base_url ) ); } else { char *out_finger = out; - assert( base.scheme.size + 1 /* ':' */ <= strlen ( base_url ) ); + assert( base.scheme.size + (size_t)1 /* ':' */ <= strlen ( base_url ) ); memcpy( out, base.scheme.buff, base.scheme.size ); out_finger += base.scheme.size; ( *out_finger ) = ':'; out_finger++; - if( rel.hostport.text.size > 0 ) { - snprintf( out_finger, strlen( rel_url ) + 1, "%s", - rel_url ); + if( rel.hostport.text.size > (size_t)0 ) { + snprintf( out_finger, strlen( rel_url ) + (size_t)1, + "%s", rel_url ); } else { - if( base.hostport.text.size > 0 ) { - assert( base.scheme.size + 1 - + base.hostport.text.size + 2 /* "//" */ <= strlen ( base_url ) ); + if( base.hostport.text.size > (size_t)0 ) { + assert( base.scheme.size + (size_t)1 + + base.hostport.text.size + (size_t)2 /* "//" */ <= strlen ( base_url ) ); memcpy( out_finger, "//", 2 ); out_finger += 2; memcpy( out_finger, base.hostport.text.buff, @@ -627,22 +627,22 @@ char *resolve_rel_url(char *base_url, char *rel_url) out_finger += base.hostport.text.size; } - if( rel.path_type == ABS_PATH ) { + if( rel.path_type == ( enum pathType ) ABS_PATH ) { strncpy( out_finger, rel_url, strlen ( rel_url ) ); } else { char temp_path = '/'; - if( base.pathquery.size == 0 ) { - base.pathquery.size = 1; + if( base.pathquery.size == (size_t)0 ) { + base.pathquery.size = (size_t)1; base.pathquery.buff = &temp_path; } - assert( base.scheme.size + 1 + base.hostport.text.size + 2 - + base.pathquery.size <= strlen ( base_url ) + 1 /* temp_path */); + assert( base.scheme.size + (size_t)1 + base.hostport.text.size + (size_t)2 + + base.pathquery.size <= strlen ( base_url ) + (size_t)1 /* temp_path */); finger = out_finger; last_slash = finger; - i = 0; + i = (size_t)0; while( ( i < base.pathquery.size ) && ( base.pathquery.buff[i] != '?' ) ) { ( *finger ) = base.pathquery.buff[i]; @@ -684,8 +684,8 @@ char *resolve_rel_url(char *base_url, char *rel_url) int parse_uri(const char *in, size_t max, uri_type *out) { int begin_path = 0; - size_t begin_hostport = 0; - size_t begin_fragment = 0; + size_t begin_hostport = (size_t)0; + size_t begin_fragment = (size_t)0; int defaultPort = 80; begin_hostport = parse_scheme(in, max, &out->scheme); @@ -697,10 +697,10 @@ int parse_uri(const char *in, size_t max, uri_type *out) out->type = RELATIVE; out->path_type = REL_PATH; } - if (begin_hostport + 1 < max && + if (begin_hostport + (size_t)1 < max && in[begin_hostport] == '/' && - in[begin_hostport + 1] == '/') { - begin_hostport += 2; + in[begin_hostport + (size_t)1] == '/') { + begin_hostport += (size_t)2; if (token_string_casecmp(&out->scheme, "https") == 0) { defaultPort = 443; } @@ -728,7 +728,7 @@ int parse_uri(const char *in, size_t max, uri_type *out) &out->fragment); } else { out->fragment.buff = NULL; - out->fragment.size = 0; + out->fragment.size = (size_t)0; } return HTTP_SUCCESS; @@ -742,10 +742,10 @@ int parse_uri_and_unescape(char *in, size_t max, uri_type *out) return ret; } - if (out->pathquery.size > 0) { + if (out->pathquery.size > (size_t)0) { remove_escaped_chars((char *)out->pathquery.buff, &out->pathquery.size); } - if (out->fragment.size > 0) { + if (out->fragment.size > (size_t)0) { remove_escaped_chars((char *)out->fragment.buff, &out->fragment.size); } diff --git a/upnp/src/genlib/service_table/service_table.c b/upnp/src/genlib/service_table/service_table.c index 173e3c1..3f09976 100644 --- a/upnp/src/genlib/service_table/service_table.c +++ b/upnp/src/genlib/service_table/service_table.c @@ -743,8 +743,8 @@ service_info *getServiceList( service_info *current = NULL; service_info *previous = NULL; IXML_NodeList *serviceNodeList = NULL; - long unsigned int NumOfServices = 0; - long unsigned int i = 0; + long unsigned int NumOfServices = 0lu; + long unsigned int i = 0lu; int fail = 0; if (getSubElement("UDN", node, &UDN) && @@ -753,7 +753,7 @@ service_info *getServiceList( (IXML_Element *)serviceList, "service"); if (serviceNodeList != NULL) { NumOfServices = ixmlNodeList_length(serviceNodeList); - for (i = 0; i < NumOfServices; i++) { + for (i = 0lu; i < NumOfServices; i++) { current_service = ixmlNodeList_item(serviceNodeList, i); fail = 0; @@ -867,8 +867,8 @@ getAllServiceList( IXML_Node * node, IXML_NodeList *deviceList = NULL; IXML_Node *currentDevice = NULL; - long unsigned int NumOfDevices = 0; - long unsigned int i = 0; + long unsigned int NumOfDevices = 0lu; + long unsigned int i = 0lu; (*out_end) = NULL; @@ -876,7 +876,7 @@ getAllServiceList( IXML_Node * node, (IXML_Element *)node, "device"); if (deviceList) { NumOfDevices = ixmlNodeList_length(deviceList); - for (i = 0; i < NumOfDevices; i++) { + for (i = 0lu; i < NumOfDevices; i++) { currentDevice = ixmlNodeList_item(deviceList, i); if (head) { end->next = getServiceList(currentDevice, @@ -922,8 +922,8 @@ removeServiceTable( IXML_Node * node, service_info *current_service = NULL; service_info *start_search = NULL; service_info *prev_service = NULL; - long unsigned int NumOfDevices = 0; - long unsigned int i = 0; + long unsigned int NumOfDevices = 0lu; + long unsigned int i = 0lu; if( getSubElement( "root", node, &root ) ) { current_service = in->serviceList; @@ -933,7 +933,7 @@ removeServiceTable( IXML_Node * node, "device" ); if( deviceList != NULL ) { NumOfDevices = ixmlNodeList_length( deviceList ); - for( i = 0; i < NumOfDevices; i++ ) { + for( i = 0lu; i < NumOfDevices; i++ ) { if( ( start_search ) && ( ( getSubElement( "UDN", node, ¤tUDN ) ) && ( UDN = getElementValue( currentUDN ) ) ) ) { @@ -944,7 +944,8 @@ removeServiceTable( IXML_Node * node, while( ( current_service ) && ( strcmp( current_service->UDN, UDN ) ) ) { current_service = current_service->next; - prev_service = current_service->next; + if( current_service != NULL) + prev_service = current_service->next; } while( ( current_service ) && ( !strcmp( current_service->UDN, UDN ) ) ) { diff --git a/upnp/src/genlib/util/membuffer.c b/upnp/src/genlib/util/membuffer.c index cb1de47..be26981 100644 --- a/upnp/src/genlib/util/membuffer.c +++ b/upnp/src/genlib/util/membuffer.c @@ -2,6 +2,7 @@ * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. + * Copyright (c) 2012 France Telecom All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -48,7 +49,7 @@ char *str_alloc(const char *str, size_t str_len) { char *s; - s = (char *)malloc(str_len + 1); + s = (char *)malloc(str_len + (size_t)1); if (s == NULL) { return NULL; /* no mem */ } @@ -96,8 +97,8 @@ static UPNP_INLINE void membuffer_initialize( membuffer *m) { m->buf = NULL; - m->length = 0; - m->capacity = 0; + m->length = (size_t)0; + m->capacity = (size_t)0; } int membuffer_set_size(membuffer *m, size_t new_length) @@ -128,14 +129,14 @@ int membuffer_set_size(membuffer *m, size_t new_length) assert(alloc_len >= new_length); - temp_buf = realloc(m->buf, alloc_len + 1); /*LEAK_FIX_MK */ + temp_buf = realloc(m->buf, alloc_len + (size_t)1); /*LEAK_FIX_MK */ /*temp_buf = Realloc( m->buf,m->length, alloc_len + 1 );LEAK_FIX_MK */ if (temp_buf == NULL) { /* try smaller size */ alloc_len = new_length; - temp_buf = realloc(m->buf, alloc_len + 1); /*LEAK_FIX_MK */ + temp_buf = realloc(m->buf, alloc_len + (size_t)1); /*LEAK_FIX_MK */ /*temp_buf = Realloc( m->buf,m->length, alloc_len + 1 );LEAK_FIX_MK */ if (temp_buf == NULL) { @@ -250,7 +251,7 @@ void membuffer_delete(membuffer * m, size_t index, size_t num_bytes) if (index + num_bytes > m->length) { num_bytes = m->length - index; /* every thing at and after index purged */ - copy_len = 0; + copy_len = (size_t)0; } else { /* calc num bytes after deleted string */ copy_len = m->length - (index + num_bytes); @@ -261,6 +262,8 @@ void membuffer_delete(membuffer * m, size_t index, size_t num_bytes) return_value = membuffer_set_size(m, new_length); /* shrinking should always work */ assert(return_value == 0); + if (return_value != 0) + return; /* don't modify until buffer is set */ m->length = new_length; diff --git a/upnp/src/genlib/util/util.c b/upnp/src/genlib/util/util.c index 9dd472a..dce06ed 100644 --- a/upnp/src/genlib/util/util.c +++ b/upnp/src/genlib/util/util.c @@ -2,6 +2,7 @@ * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. + * Copyright (c) 2012 France Telecom All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -44,14 +45,14 @@ void linecopy(char dest[LINE_SIZE], const char *src) { - strncpy(dest, src, LINE_SIZE - 1); + strncpy(dest, src, LINE_SIZE - (size_t)1); /* null-terminate if len(src) >= LINE_SIZE. */ dest[LINE_SIZE - 1] = '\0'; } void namecopy(char dest[NAME_SIZE], const char *src) { - strncpy(dest, src, NAME_SIZE - 1); + strncpy(dest, src, NAME_SIZE - (size_t)1); /* null-terminate if len(src) >= NAME_SIZE. */ dest[NAME_SIZE - 1] = '\0'; } @@ -60,7 +61,7 @@ void linecopylen(char dest[LINE_SIZE], const char *src, size_t srclen) { size_t len; - len = srclen < (LINE_SIZE - 1) ? srclen : (LINE_SIZE - 1); + len = srclen < (LINE_SIZE - (size_t)1) ? srclen : (LINE_SIZE - (size_t)1); strncpy(dest, src, len); dest[len] = '\0'; } diff --git a/upnp/src/inc/httpparser.h b/upnp/src/inc/httpparser.h index d5a1f52..e5d1bfe 100644 --- a/upnp/src/inc/httpparser.h +++ b/upnp/src/inc/httpparser.h @@ -2,6 +2,7 @@ * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. + * Copyright (c) 2012 France Telecom All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -433,7 +434,7 @@ parse_status_t parser_append( INOUT http_parser_t* parser, * PARSE_NO_MATCH -- failure to match pattern 'fmt' * PARSE_FAILURE -- 'str' is bad input ************************************************************************/ -int matchstr( IN char *str, IN size_t slen, IN const char* fmt, ... ); +parse_status_t matchstr( IN char *str, IN size_t slen, IN const char* fmt, ... ); /************************************************************************ * Function: raw_to_int diff --git a/upnp/src/inc/membuffer.h b/upnp/src/inc/membuffer.h index af492fe..560d942 100644 --- a/upnp/src/inc/membuffer.h +++ b/upnp/src/inc/membuffer.h @@ -2,6 +2,7 @@ * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. + * Copyright (c) 2012 France Telecom All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -62,7 +63,7 @@ typedef struct { /*! used to increase size; MUST be > 0; (read/write). */ size_t size_inc; /*! default value of size_inc. */ -#define MEMBUF_DEF_SIZE_INC 5 +#define MEMBUF_DEF_SIZE_INC (size_t)5 } membuffer; #ifdef __cplusplus diff --git a/upnp/src/inc/service_table.h b/upnp/src/inc/service_table.h index 2112f8a..0527a14 100644 --- a/upnp/src/inc/service_table.h +++ b/upnp/src/inc/service_table.h @@ -2,6 +2,7 @@ * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. + * Copyright (c) 2012 France Telecom All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -49,7 +50,7 @@ extern "C" { #include #include -#define SID_SIZE 41 +#define SID_SIZE (size_t)41 #ifdef INCLUDE_DEVICE_APIS diff --git a/upnp/src/inc/ssdplib.h b/upnp/src/inc/ssdplib.h index dea00fe..40e5b28 100644 --- a/upnp/src/inc/ssdplib.h +++ b/upnp/src/inc/ssdplib.h @@ -5,7 +5,7 @@ * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. - * Copyright (C) 2011 France Telecom All rights reserved. + * Copyright (C) 2011-2012 France Telecom All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -73,7 +73,7 @@ typedef enum SsdpSearchType { SSDP_SERVICE } SType; -#define BUFSIZE 2500 +#define BUFSIZE (size_t)2500 #define SSDP_IP "239.255.255.250" #define SSDP_IPV6_LINKLOCAL "FF02::C" #define SSDP_IPV6_SITELOCAL "FF05::C" diff --git a/upnp/src/inc/upnpapi.h b/upnp/src/inc/upnpapi.h index 54a4672..110fda6 100644 --- a/upnp/src/inc/upnpapi.h +++ b/upnp/src/inc/upnpapi.h @@ -174,7 +174,7 @@ Upnp_Handle_Type GetClientHandleInfo( */ Upnp_Handle_Type GetDeviceHandleInfo( /*! [in] Address family. */ - const int AddressFamily, + const unsigned short AddressFamily, /*! [out] Device handle pointer. */ int *device_handle_out, /*! [out] Device handle structure passed by this function. */ diff --git a/upnp/src/inc/upnputil.h b/upnp/src/inc/upnputil.h index 5dc7d37..7236d6d 100644 --- a/upnp/src/inc/upnputil.h +++ b/upnp/src/inc/upnputil.h @@ -5,6 +5,7 @@ * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. + * Copyright (c) 2012 France Telecom All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -109,7 +110,7 @@ void linecopylen( #endif /* Size of the errorBuffer variable, passed to the strerror_r() function */ -#define ERROR_BUFFER_LEN 256 +#define ERROR_BUFFER_LEN (size_t)256 /* C specific */ /* VC needs these in C++ mode too (do other compilers?) */ diff --git a/upnp/src/ssdp/ssdp_device.c b/upnp/src/ssdp/ssdp_device.c index abdac8e..d4fb51c 100644 --- a/upnp/src/ssdp/ssdp_device.c +++ b/upnp/src/ssdp/ssdp_device.c @@ -187,7 +187,7 @@ static int NewRequestHandler( char buf_ntop[INET6_ADDRSTRLEN]; int ret = UPNP_E_SUCCESS; - ReplySock = socket(DestAddr->sa_family, SOCK_DGRAM, 0); + ReplySock = socket((int)DestAddr->sa_family, SOCK_DGRAM, 0); if (ReplySock == INVALID_SOCKET) { strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__, @@ -320,7 +320,7 @@ static void CreateServicePacket( /*! [out] Output buffer filled with HTTP statement. */ char **packet, /*! [in] Address family of the HTTP request. */ - int AddressFamily, + unsigned short AddressFamily, /*! [in] PowerState as defined by UPnP Low Power. */ int PowerState, /*! [in] SleepPeriod as defined by UPnP Low Power. */ @@ -336,7 +336,7 @@ static void CreateServicePacket( * Notf == 1 means service advertisement, * Notf == 2 means reply */ membuffer_init(&buf); - buf.size_inc = 30; + buf.size_inc = (size_t)30; *packet = NULL; if (msg_type == MSGTYPE_REPLY) { if (PowerState > 0) { @@ -447,11 +447,11 @@ int DeviceAdvertisement(char *DevType, int RootDev, char *Udn, char *Location, memset(&__ss, 0, sizeof(__ss)); memset(Mil_Usn, 0, sizeof(Mil_Usn)); if (AddressFamily == AF_INET) { - DestAddr4->sin_family = AF_INET; + DestAddr4->sin_family = (unsigned short)AF_INET; inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); DestAddr4->sin_port = htons(SSDP_PORT); } else if (AddressFamily == AF_INET6) { - DestAddr6->sin6_family = AF_INET6; + DestAddr6->sin6_family = (unsigned short)AF_INET6; inet_pton(AF_INET6, (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr); @@ -656,11 +656,11 @@ int ServiceAdvertisement(char *Udn, char *ServType, char *Location, memset(Mil_Usn, 0, sizeof(Mil_Usn)); szReq[0] = NULL; if (AddressFamily == AF_INET) { - DestAddr4->sin_family = AF_INET; + DestAddr4->sin_family = (unsigned short)AF_INET; inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); DestAddr4->sin_port = htons(SSDP_PORT); } else if (AddressFamily == AF_INET6) { - DestAddr6->sin6_family = AF_INET6; + DestAddr6->sin6_family = (unsigned short)AF_INET6; inet_pton(AF_INET6, (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr); @@ -783,11 +783,11 @@ int DeviceShutdown(char *DevType, int RootDev, char *Udn, char *_Server, memset(&__ss, 0, sizeof(__ss)); memset(Mil_Usn, 0, sizeof(Mil_Usn)); if (AddressFamily == AF_INET) { - DestAddr4->sin_family = AF_INET; + DestAddr4->sin_family = (unsigned short)AF_INET; inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); DestAddr4->sin_port = htons(SSDP_PORT); } else if (AddressFamily == AF_INET6) { - DestAddr6->sin6_family = AF_INET6; + DestAddr6->sin6_family = (unsigned short)AF_INET6; inet_pton(AF_INET6, (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr); diff --git a/upnp/src/ssdp/ssdp_server.c b/upnp/src/ssdp/ssdp_server.c index 354bf06..fdda33e 100644 --- a/upnp/src/ssdp/ssdp_server.c +++ b/upnp/src/ssdp/ssdp_server.c @@ -346,7 +346,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd, "ServiceType not found \n"); continue; } - tmpNode2 = ixmlNodeList_item(tmpNodeList, 0); + tmpNode2 = ixmlNodeList_item(tmpNodeList, 0lu); if (!tmpNode2) continue; textNode = ixmlNode_getFirstChild(tmpNode2); @@ -404,7 +404,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd, SInfo->SleepPeriod, SInfo->RegistrationState); } else if (atoi(strrchr (ServiceType, ':') + 1) == - atoi(&servType[strlen(servType) - 1])) { + atoi(&servType[strlen(servType) - (size_t)1])) { UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "ServiceType=%s and search servType=%s MATCH\n", ServiceType, servType); @@ -457,7 +457,7 @@ int unique_service_name(char *cmd, SsdpEvent *Evt) char *ptr2 = NULL; char *ptr3 = NULL; int CommandFound = 0; - size_t n = 0; + size_t n = (size_t)0; int rc = 0; if (strstr(cmd, "uuid:schemas") != NULL) { @@ -480,7 +480,7 @@ int unique_service_name(char *cmd, SsdpEvent *Evt) return -1; ptr1 = strstr(cmd, ":"); if (ptr1 != NULL) { - n = (size_t) (ptr3 - ptr1); + n = (size_t)ptr3 - (size_t)ptr1; strncpy(TempBuf, ptr1, n); TempBuf[n] = '\0'; rc = snprintf(Evt->DeviceType, sizeof(Evt->DeviceType), @@ -493,7 +493,7 @@ int unique_service_name(char *cmd, SsdpEvent *Evt) } if ((TempPtr = strstr(cmd, "uuid")) != NULL) { if ((Ptr = strstr(cmd, "::")) != NULL) { - n = (size_t) (Ptr - TempPtr); + n = (size_t)Ptr - (size_t)TempPtr; strncpy(Evt->UDN, TempPtr, n); Evt->UDN[n] = '\0'; } else { @@ -521,7 +521,7 @@ int unique_service_name(char *cmd, SsdpEvent *Evt) if ((TempPtr = strstr(cmd, "::upnp:rootdevice")) != NULL) { /* Everything before "::upnp::rootdevice" is the UDN. */ if (TempPtr != cmd) { - n = (size_t) (TempPtr - cmd); + n = (size_t)TempPtr - (size_t)cmd; strncpy(Evt->UDN, cmd, n); Evt->UDN[n] = 0; CommandFound = 1; @@ -595,14 +595,14 @@ static UPNP_INLINE int valid_ssdp_msg( memptr hdr_value; /* check for valid methods - NOTIFY or M-SEARCH */ - if (hmsg->method != HTTPMETHOD_NOTIFY && - hmsg->method != HTTPMETHOD_MSEARCH && - hmsg->request_method != HTTPMETHOD_MSEARCH) { + if (hmsg->method != (http_method_t)HTTPMETHOD_NOTIFY && + hmsg->method != (http_method_t)HTTPMETHOD_MSEARCH && + hmsg->request_method != (http_method_t)HTTPMETHOD_MSEARCH) { return FALSE; } - if (hmsg->request_method != HTTPMETHOD_MSEARCH) { + if (hmsg->request_method != (http_method_t)HTTPMETHOD_MSEARCH) { /* check PATH == "*" */ - if (hmsg->uri.type != RELATIVE || + if (hmsg->uri.type != (enum uriType)RELATIVE || strncmp("*", hmsg->uri.pathquery.buff, hmsg->uri.pathquery.size) != 0) { return FALSE; @@ -642,8 +642,8 @@ static UPNP_INLINE int start_event_handler( parser = &data->parser; status = parser_parse(parser); - if (status == PARSE_FAILURE) { - if (parser->msg.method != HTTPMETHOD_NOTIFY || + if (status == (parse_status_t)PARSE_FAILURE) { + if (parser->msg.method != (http_method_t)HTTPMETHOD_NOTIFY || !parser->valid_ssdp_notify_hack) { UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__, "SSDP recvd bad msg code = %d\n", status); @@ -651,7 +651,7 @@ static UPNP_INLINE int start_event_handler( goto error_handler; } /* valid notify msg */ - } else if (status != PARSE_SUCCESS) { + } else if (status != (parse_status_t)PARSE_SUCCESS) { UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__, "SSDP recvd bad msg code = %d\n", status); @@ -683,8 +683,8 @@ static void ssdp_event_handler_thread( if (start_event_handler(the_data) != 0) return; /* send msg to device or ctrlpt */ - if (hmsg->method == HTTPMETHOD_NOTIFY || - hmsg->request_method == HTTPMETHOD_MSEARCH) { + if (hmsg->method == (http_method_t)HTTPMETHOD_NOTIFY || + hmsg->request_method == (http_method_t)HTTPMETHOD_MSEARCH) { #ifdef INCLUDE_CLIENT_APIS ssdp_handle_ctrlpt_msg(hmsg, &data->dest_addr, @@ -739,7 +739,7 @@ void readFromSSDPSocket(SOCKET socket) data = NULL; } } - byteReceived = recvfrom(socket, requestBuf, BUFSIZE - 1, 0, + byteReceived = recvfrom(socket, requestBuf, BUFSIZE - (size_t)1, 0, (struct sockaddr *)&__ss, &socklen); if (byteReceived > 0) { requestBuf[byteReceived] = '\0'; @@ -790,7 +790,7 @@ static int create_ssdp_sock_v4( { char errorBuffer[ERROR_BUFFER_LEN]; int onOff; - u_char ttl = 4; + u_char ttl = (u_char)4; struct ip_mreq ssdpMcastAddr; struct sockaddr_storage __ss; struct sockaddr_in *ssdpAddr4 = (struct sockaddr_in *)&__ss; @@ -834,7 +834,7 @@ static int create_ssdp_sock_v4( } #endif /* BSD, __OSX__, __APPLE__ */ memset(&__ss, 0, sizeof(__ss)); - ssdpAddr4->sin_family = AF_INET; + ssdpAddr4->sin_family = (unsigned short)AF_INET; ssdpAddr4->sin_addr.s_addr = htonl(INADDR_ANY); ssdpAddr4->sin_port = htons(SSDP_PORT); ret = bind(*ssdpSock, (struct sockaddr *)ssdpAddr4, sizeof(*ssdpAddr4)); @@ -1215,7 +1215,7 @@ int get_ssdp_sockets(MiniServerSockArray * out) #endif /* IPv6 */ #endif /* INCLUDE_CLIENT_APIS */ /* Create the IPv4 socket for SSDP */ - if (strlen(gIF_IPV4) > 0) { + if (strlen(gIF_IPV4) > (size_t)0) { retVal = create_ssdp_sock_v4(&out->ssdpSock4); if (retVal != UPNP_E_SUCCESS) { #ifdef INCLUDE_CLIENT_APIS @@ -1230,7 +1230,7 @@ int get_ssdp_sockets(MiniServerSockArray * out) out->ssdpSock4 = INVALID_SOCKET; /* Create the IPv6 socket for SSDP */ #ifdef UPNP_ENABLE_IPV6 - if (strlen(gIF_IPV6) > 0) { + if (strlen(gIF_IPV6) > (size_t)0) { retVal = create_ssdp_sock_v6(&out->ssdpSock6); if (retVal != UPNP_E_SUCCESS) { shutdown(out->ssdpSock4, SD_BOTH); @@ -1245,7 +1245,7 @@ int get_ssdp_sockets(MiniServerSockArray * out) } } else out->ssdpSock6 = INVALID_SOCKET; - if (strlen(gIF_IPV6_ULA_GUA) > 0) { + if (strlen(gIF_IPV6_ULA_GUA) > (size_t)0) { retVal = create_ssdp_sock_v6_ula_gua(&out->ssdpSock6UlaGua); if (retVal != UPNP_E_SUCCESS) { shutdown(out->ssdpSock4, SD_BOTH); diff --git a/upnp/src/urlconfig/urlconfig.c b/upnp/src/urlconfig/urlconfig.c index 5cf6654..3251da6 100644 --- a/upnp/src/urlconfig/urlconfig.c +++ b/upnp/src/urlconfig/urlconfig.c @@ -83,16 +83,18 @@ addrToString( IN const struct sockaddr *addr, IN size_t ipaddr_port_size ) { char buf_ntop[INET6_ADDRSTRLEN]; - int rc; + int rc = 0; if( addr->sa_family == AF_INET ) { struct sockaddr_in* sa4 = (struct sockaddr_in*)addr; inet_ntop(AF_INET, &sa4->sin_addr, buf_ntop, sizeof(buf_ntop) ); - rc = snprintf( ipaddr_port, ipaddr_port_size, "%s:%d", buf_ntop, ntohs( sa4->sin_port ) ); + rc = snprintf( ipaddr_port, ipaddr_port_size, "%s:%d", buf_ntop, + (int)ntohs( sa4->sin_port ) ); } else if( addr->sa_family == AF_INET6 ) { struct sockaddr_in6* sa6 = (struct sockaddr_in6*)addr; inet_ntop(AF_INET6, &sa6->sin6_addr, buf_ntop, sizeof(buf_ntop) ); - rc = snprintf( ipaddr_port, ipaddr_port_size, "[%s]:%d", buf_ntop, ntohs( sa6->sin6_port ) ); + rc = snprintf( ipaddr_port, ipaddr_port_size, "[%s]:%d", buf_ntop, + (int)ntohs( sa6->sin6_port ) ); } if (rc < 0 || (unsigned int) rc >= ipaddr_port_size) return UPNP_E_BUFFER_TOO_SMALL; @@ -142,10 +144,10 @@ static UPNP_INLINE int calc_alias( else aliasPtr = alias; new_alias_len = root_len + strlen(temp_str) + strlen(aliasPtr); - alias_temp = malloc(new_alias_len + 1); + alias_temp = malloc(new_alias_len + (size_t)1); if (alias_temp == NULL) return UPNP_E_OUTOF_MEMORY; - memset(alias_temp, 0, new_alias_len + 1); + memset(alias_temp, 0, new_alias_len + (size_t)1); strncpy(alias_temp, rootPath, root_len); alias_temp[root_len] = '\0'; strncat(alias_temp, temp_str, strlen(temp_str)); @@ -185,7 +187,7 @@ static UPNP_INLINE int calc_descURL( assert(alias != NULL && strlen(alias) > 0); len = strlen(http_scheme) + strlen(ipPortStr) + strlen(alias); - if (len > (LINE_SIZE - 1)) + if (len > ((size_t)LINE_SIZE - (size_t)1)) return UPNP_E_URL_TOO_BIG; strncpy(descURL, http_scheme, strlen(http_scheme)); descURL[strlen(http_scheme)] = '\0'; @@ -279,7 +281,7 @@ static int config_description_doc( } } else { /* urlbase found */ - urlbase_node = ixmlNodeList_item(baseList, 0); + urlbase_node = ixmlNodeList_item(baseList, 0lu); assert(urlbase_node != NULL); textNode = ixmlNode_getFirstChild(urlbase_node); if (textNode == NULL) { @@ -319,7 +321,7 @@ static int config_description_doc( } /* add trailing '/' if missing */ if (url_str.buf[url_str.length - 1] != '/') { - if (membuffer_append(&url_str, "/", 1) != 0) { + if (membuffer_append(&url_str, "/", (size_t)1) != 0) { goto error_handler; } }