From ad29c28dc445a12d4313c82946a779d6a67cb718 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Wed, 13 Dec 2017 13:33:32 -0800 Subject: [PATCH] fix warning according to prefast code analysis --- source/pdo_sqlsrv/pdo_dbh.cpp | 2 +- source/pdo_sqlsrv/pdo_util.cpp | 2 +- source/shared/core_conn.cpp | 9 ++++----- source/shared/core_sqlsrv.h | 9 +++++---- source/shared/core_stmt.cpp | 6 +++--- source/shared/core_util.cpp | 2 +- source/sqlsrv/php_sqlsrv.h | 2 +- source/sqlsrv/stmt.cpp | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/source/pdo_sqlsrv/pdo_dbh.cpp b/source/pdo_sqlsrv/pdo_dbh.cpp index c0a7ea4f..471a3a90 100644 --- a/source/pdo_sqlsrv/pdo_dbh.cpp +++ b/source/pdo_sqlsrv/pdo_dbh.cpp @@ -1301,7 +1301,7 @@ char * pdo_sqlsrv_dbh_last_id( _Inout_ pdo_dbh_t *dbh, _In_z_ const char *name, sqlsrv_malloc_auto_ptr wsql_string; unsigned int wsql_len; - wsql_string = utf16_string_from_mbcs_string( SQLSRV_ENCODING_CHAR, reinterpret_cast( last_insert_id_query ), strlen(last_insert_id_query), &wsql_len ); + wsql_string = utf16_string_from_mbcs_string( SQLSRV_ENCODING_CHAR, reinterpret_cast( last_insert_id_query ), static_cast( strlen( last_insert_id_query )), &wsql_len ); CHECK_CUSTOM_ERROR( wsql_string == 0, driver_stmt, SQLSRV_ERROR_QUERY_STRING_ENCODING_TRANSLATE, get_last_error_message() ) { throw core::CoreException(); diff --git a/source/pdo_sqlsrv/pdo_util.cpp b/source/pdo_sqlsrv/pdo_util.cpp index 51e37809..c11e4ae5 100644 --- a/source/pdo_sqlsrv/pdo_util.cpp +++ b/source/pdo_sqlsrv/pdo_util.cpp @@ -33,7 +33,7 @@ char EXCEPTION_PROPERTY_ERRORINFO[] = "errorInfo"; const int MAX_DIGITS = 11; // +-2 billion = 10 digits + 1 for the sign if negative // the warning message is not the error message alone; it must take WARNING_TEMPLATE above into consideration without the formats -const int WARNING_MIN_LENGTH = strlen(WARNING_TEMPLATE) - strlen("%1!s!%2!d!%3!s!"); +const int WARNING_MIN_LENGTH = static_cast( strlen( WARNING_TEMPLATE ) - strlen( "%1!s!%2!d!%3!s!" )); // buffer used to hold a formatted log message prior to actually logging it. const int LOG_MSG_SIZE = 2048; diff --git a/source/shared/core_conn.cpp b/source/shared/core_conn.cpp index 83694f5d..5e0535b0 100644 --- a/source/shared/core_conn.cpp +++ b/source/shared/core_conn.cpp @@ -305,7 +305,7 @@ bool core_compare_error_state( _In_ sqlsrv_conn* conn, _In_ SQLRETURN rc, _In_ if( SQL_SUCCEEDED( rc ) ) return false; - SQLCHAR state[ SQL_SQLSTATE_BUFSIZE ]; + SQLCHAR state[ SQL_SQLSTATE_BUFSIZE ] = { 0 }; SQLSMALLINT len; SQLRETURN sr = SQLGetDiagField( SQL_HANDLE_DBC, conn->handle(), 1, SQL_DIAG_SQLSTATE, state, SQL_SQLSTATE_BUFSIZE, &len ); @@ -321,13 +321,12 @@ bool core_compare_error_state( _In_ sqlsrv_conn* conn, _In_ SQLRETURN rc, _In_ bool core_search_odbc_driver_unix( _In_ DRIVER_VERSION driver_version ) { +#ifndef _WIN32 char szBuf[DEFAULT_CONN_STR_LEN+1]; // use a large enough buffer size WORD cbBufMax = DEFAULT_CONN_STR_LEN; WORD cbBufOut; char *pszBuf = szBuf; - bool found_driver = false; -#ifndef _WIN32 // get all the names of the installed drivers delimited by null characters if(! SQLGetInstalledDrivers( szBuf, cbBufMax, &cbBufOut ) ) { @@ -966,8 +965,8 @@ void load_configure_ksp( _Inout_ sqlsrv_conn* conn TSRMLS_DC ) char* ksp_name = Z_STRVAL_P( conn->ce_option.ksp_name ); char* ksp_path = Z_STRVAL_P( conn->ce_option.ksp_path ); - unsigned int name_len = Z_STRLEN_P( conn->ce_option.ksp_name ); - unsigned int key_size = conn->ce_option.key_size; + unsigned int name_len = static_cast( Z_STRLEN_P( conn->ce_option.ksp_name )); + unsigned int key_size = static_cast( conn->ce_option.key_size ); sqlsrv_malloc_auto_ptr ksp_data; diff --git a/source/shared/core_sqlsrv.h b/source/shared/core_sqlsrv.h index d1392d1f..e138d212 100644 --- a/source/shared/core_sqlsrv.h +++ b/source/shared/core_sqlsrv.h @@ -2267,10 +2267,11 @@ namespace core { SQLRETURN r; SQLHDESC hIpd = NULL; core::SQLGetStmtAttr( stmt, SQL_ATTR_IMP_PARAM_DESC, &hIpd, 0, 0 ); - r = ::SQLSetDescField( hIpd, rec_num, fld_id, value_ptr, str_len ); - - CHECK_SQL_ERROR_OR_WARNING( r, stmt ) { - throw CoreException(); + if( value_ptr ) { + r = ::SQLSetDescField( hIpd, rec_num, fld_id, value_ptr, str_len ); + CHECK_SQL_ERROR_OR_WARNING( r, stmt ) { + throw CoreException(); + } } } diff --git a/source/shared/core_stmt.cpp b/source/shared/core_stmt.cpp index d8bca088..4fa98abc 100644 --- a/source/shared/core_stmt.cpp +++ b/source/shared/core_stmt.cpp @@ -2670,12 +2670,12 @@ void adjustInputPrecision( _Inout_ zval* param_z, _In_ SQLSMALLINT decimal_digit return; } std::vector digits; - char* ptr = ZSTR_VAL( Z_STR_P( param_z )); + unsigned char* ptr = reinterpret_cast(ZSTR_VAL( Z_STR_P( param_z ))); bool isNeg = false; bool isScientificNot = false; char scientificChar = ' '; short scientificExp = 0; - if( strchr( ptr, 'e' ) || strchr( ptr, 'E' )){ + if( strchr( reinterpret_cast( ptr ), 'e' ) || strchr( reinterpret_cast( ptr ), 'E' )){ isScientificNot = true; } // parse digits in param_z into the vector digits @@ -2754,7 +2754,7 @@ void adjustInputPrecision( _Inout_ zval* param_z, _In_ SQLSMALLINT decimal_digit // check if the last digit to be popped is greater than 5, if so, the digit before it needs to round up carryOver = digits.back() >= 5; digits.pop_back(); - backInd = digits.size() - 1; + backInd = static_cast(digits.size() - 1); // round up from the end until no more carry over while( carryOver && backInd >= 0 ){ if( digits.at( backInd ) != 9 ){ diff --git a/source/shared/core_util.cpp b/source/shared/core_util.cpp index 8453a6b8..73e8feff 100644 --- a/source/shared/core_util.cpp +++ b/source/shared/core_util.cpp @@ -263,7 +263,7 @@ bool core_sqlsrv_get_odbc_error( _Inout_ sqlsrv_context& ctx, _In_ int record_nu } // We need to calculate number of characters - SQLLEN wsqlstate_len = sizeof( wsqlstate ) / sizeof( SQLWCHAR ); + SQLINTEGER wsqlstate_len = sizeof( wsqlstate ) / sizeof( SQLWCHAR ); SQLLEN sqlstate_len = 0; convert_string_from_utf16(enc, wsqlstate, wsqlstate_len, (char**)&error->sqlstate, sqlstate_len); diff --git a/source/sqlsrv/php_sqlsrv.h b/source/sqlsrv/php_sqlsrv.h index baa0b2c1..54c446b2 100644 --- a/source/sqlsrv/php_sqlsrv.h +++ b/source/sqlsrv/php_sqlsrv.h @@ -157,7 +157,7 @@ void __cdecl sqlsrv_conn_dtor( _Inout_ zend_resource *rsrc TSRMLS_DC ); // holds the field names for reuse by sqlsrv_fetch_array/object as keys struct sqlsrv_fetch_field_name { char* name; - unsigned int len; + SQLLEN len; }; struct stmt_option_ss_scrollable : public stmt_option_functor { diff --git a/source/sqlsrv/stmt.cpp b/source/sqlsrv/stmt.cpp index a0f88e94..e495ebf1 100644 --- a/source/sqlsrv/stmt.cpp +++ b/source/sqlsrv/stmt.cpp @@ -1229,7 +1229,7 @@ void bind_params( _Inout_ ss_sqlsrv_stmt* stmt TSRMLS_DC ) } // bind the parameter SQLSRV_ASSERT( value_z != NULL, "bind_params: value_z is null." ); - core_sqlsrv_bind_param( stmt, index, direction, value_z, php_out_type, encoding, sql_type, column_size, + core_sqlsrv_bind_param( stmt, static_cast( index ), direction, value_z, php_out_type, encoding, sql_type, column_size, decimal_digits TSRMLS_CC ); } ZEND_HASH_FOREACH_END();