Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimized warnings during compilation #1205

Merged
merged 3 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions source/pdo_sqlsrv/pdo_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void pdo_error_dtor( _Inout_ zval* elem ) {

PHP_MINIT_FUNCTION(pdo_sqlsrv)
{
SQLSRV_UNUSED( type );
// SQLSRV_UNUSED( type );

// our global variables are initialized in the RINIT function
#if defined(ZTS)
Expand Down Expand Up @@ -185,7 +185,7 @@ PHP_MSHUTDOWN_FUNCTION(pdo_sqlsrv)
{
try {

SQLSRV_UNUSED( type );
// SQLSRV_UNUSED( type );

UNREGISTER_INI_ENTRIES();

Expand Down Expand Up @@ -213,8 +213,8 @@ PHP_MSHUTDOWN_FUNCTION(pdo_sqlsrv)

PHP_RINIT_FUNCTION(pdo_sqlsrv)
{
SQLSRV_UNUSED( module_number );
SQLSRV_UNUSED( type );
// SQLSRV_UNUSED( module_number );
// SQLSRV_UNUSED( type );

#if defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
Expand Down Expand Up @@ -247,8 +247,8 @@ PHP_RINIT_FUNCTION(pdo_sqlsrv)

PHP_RSHUTDOWN_FUNCTION(pdo_sqlsrv)
{
SQLSRV_UNUSED( module_number );
SQLSRV_UNUSED( type );
// SQLSRV_UNUSED( module_number );
// SQLSRV_UNUSED( type );

PDO_LOG_NOTICE("pdo_sqlsrv: entering rshutdown");

Expand Down
6 changes: 3 additions & 3 deletions source/pdo_sqlsrv/pdo_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ pdo_error PDO_ERRORS[] = {
{ UINT_MAX, {} }
};

bool pdo_sqlsrv_handle_env_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned int sqlsrv_error_code, _In_opt_ bool warning,
bool pdo_sqlsrv_handle_env_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned int sqlsrv_error_code, _In_opt_ int warning,
_In_opt_ va_list* print_args )
{
SQLSRV_ASSERT((ctx != NULL), "pdo_sqlsrv_handle_env_error: sqlsrv_context was null");
Expand All @@ -488,7 +488,7 @@ bool pdo_sqlsrv_handle_env_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned
}

// pdo error handler for the dbh context.
bool pdo_sqlsrv_handle_dbh_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned int sqlsrv_error_code, _In_opt_ bool warning,
bool pdo_sqlsrv_handle_dbh_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned int sqlsrv_error_code, _In_opt_ int warning,
_In_opt_ va_list* print_args )
{
pdo_dbh_t* dbh = reinterpret_cast<pdo_dbh_t*>( ctx.driver());
Expand Down Expand Up @@ -520,7 +520,7 @@ bool pdo_sqlsrv_handle_dbh_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned
}

// PDO error handler for the statement context.
bool pdo_sqlsrv_handle_stmt_error(_Inout_ sqlsrv_context& ctx, _In_opt_ unsigned int sqlsrv_error_code, _In_opt_ bool warning,
bool pdo_sqlsrv_handle_stmt_error(_Inout_ sqlsrv_context& ctx, _In_opt_ unsigned int sqlsrv_error_code, _In_opt_ int warning,
_In_opt_ va_list* print_args)
{
pdo_stmt_t* pdo_stmt = reinterpret_cast<pdo_stmt_t*>(ctx.driver());
Expand Down
6 changes: 3 additions & 3 deletions source/pdo_sqlsrv/php_pdo_sqlsrv_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ struct pdo_error {
// called when an error occurs in the core layer. These routines are set as the error_callback in a
// context. The context is passed to this function since it contains the function

bool pdo_sqlsrv_handle_env_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned int sqlsrv_error_code, _In_opt_ bool warning,
bool pdo_sqlsrv_handle_env_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned int sqlsrv_error_code, _In_opt_ int warning,
_In_opt_ va_list* print_args );
bool pdo_sqlsrv_handle_dbh_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned int sqlsrv_error_code, _In_opt_ bool warning,
bool pdo_sqlsrv_handle_dbh_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned int sqlsrv_error_code, _In_opt_ int warning,
_In_opt_ va_list* print_args );
bool pdo_sqlsrv_handle_stmt_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned int sqlsrv_error_code, _In_opt_ bool warning,
bool pdo_sqlsrv_handle_stmt_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned int sqlsrv_error_code, _In_opt_ int warning,
_In_opt_ va_list* print_args );

// common routine to transfer a sqlsrv_context's error to a PDO zval
Expand Down
8 changes: 4 additions & 4 deletions source/shared/core_results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ SQLRETURN sqlsrv_buffered_result_set::string_to_double( _In_ SQLSMALLINT field_i
double* number_data = reinterpret_cast<double*>(buffer);
try {
*number_data = std::stod(std::string(string_data));
} catch (const std::logic_error& err) {
} catch (const std::logic_error& ) {
last_error = new (sqlsrv_malloc(sizeof(sqlsrv_error))) sqlsrv_error((SQLCHAR*) "22003", (SQLCHAR*) "Numeric value out of range", 103);
return SQL_ERROR;
}
Expand All @@ -1091,7 +1091,7 @@ SQLRETURN sqlsrv_buffered_result_set::wstring_to_double( _In_ SQLSMALLINT field_
#else
*number_data = std::stod(getUTF8StringFromString(string_data));
#endif // _WIN32
} catch (const std::logic_error& err) {
} catch (const std::logic_error& ) {
last_error = new (sqlsrv_malloc(sizeof(sqlsrv_error))) sqlsrv_error((SQLCHAR*) "22003", (SQLCHAR*) "Numeric value out of range", 103);
return SQL_ERROR;
}
Expand All @@ -1112,7 +1112,7 @@ SQLRETURN sqlsrv_buffered_result_set::string_to_long( _In_ SQLSMALLINT field_ind
LONG* number_data = reinterpret_cast<LONG*>(buffer);
try {
*number_data = std::stol(std::string(string_data));
} catch (const std::logic_error& err) {
} catch (const std::logic_error& ) {
last_error = new (sqlsrv_malloc(sizeof(sqlsrv_error))) sqlsrv_error((SQLCHAR*) "22003", (SQLCHAR*) "Numeric value out of range", 103);
return SQL_ERROR;
}
Expand All @@ -1137,7 +1137,7 @@ SQLRETURN sqlsrv_buffered_result_set::wstring_to_long( _In_ SQLSMALLINT field_in
#else
*number_data = std::stol(getUTF8StringFromString(string_data));
#endif // _WIN32
} catch (const std::logic_error& err) {
} catch (const std::logic_error& ) {
last_error = new (sqlsrv_malloc(sizeof(sqlsrv_error))) sqlsrv_error((SQLCHAR*) "22003", (SQLCHAR*) "Numeric value out of range", 103);
return SQL_ERROR;
}
Expand Down
18 changes: 9 additions & 9 deletions source/shared/core_sqlsrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ struct sqlsrv_conn;
// a driver specific callback for processing errors.
// ctx - the context holding the handles
// sqlsrv_error_code - specific error code to return.
typedef bool (*error_callback)( _Inout_ sqlsrv_context& ctx, _In_ unsigned int sqlsrv_error_code, _In_ bool error, _In_opt_ va_list* print_args );
typedef bool (*error_callback)( _Inout_ sqlsrv_context& ctx, _In_ unsigned int sqlsrv_error_code, _In_ int error, _In_opt_ va_list* print_args );

// sqlsrv_context
// a context holds relevant information to be passed with a connection and statement objects.
Expand Down Expand Up @@ -1931,7 +1931,7 @@ DWORD core_sqlsrv_format_message( _Out_ char* output_buffer, _In_ unsigned outpu

// convenience functions that overload either a reference or a pointer so we can use
// either in the CHECK_* functions.
inline bool call_error_handler( _Inout_ sqlsrv_context& ctx, _In_ unsigned long sqlsrv_error_code, _In_ bool warning, ... )
inline bool call_error_handler( _Inout_ sqlsrv_context& ctx, _In_ unsigned long sqlsrv_error_code, _In_ int warning, ... )
{
va_list print_params;
va_start( print_params, warning );
Expand All @@ -1940,7 +1940,7 @@ inline bool call_error_handler( _Inout_ sqlsrv_context& ctx, _In_ unsigned long
return ignored;
}

inline bool call_error_handler( _Inout_ sqlsrv_context* ctx, _In_ unsigned long sqlsrv_error_code, _In_ bool warning, ... )
inline bool call_error_handler( _Inout_ sqlsrv_context* ctx, _In_ unsigned long sqlsrv_error_code, _In_ int warning, ... )
{
va_list print_params;
va_start( print_params, warning );
Expand Down Expand Up @@ -1985,7 +1985,7 @@ inline bool is_truncated_warning( _In_ SQLCHAR* state )
bool flag##unique = (condition); \
bool ignored##unique = true; \
if (flag##unique) { \
ignored##unique = call_error_handler( context, ssphp, /*warning*/false, ## __VA_ARGS__ ); \
ignored##unique = call_error_handler( context, ssphp, /*warning*/0, ## __VA_ARGS__ ); \
} \
if( !ignored##unique )

Expand All @@ -2005,7 +2005,7 @@ inline bool is_truncated_warning( _In_ SQLCHAR* state )
#define CHECK_WARNING_AS_ERROR_UNIQUE( unique, condition, context, ssphp, ... ) \
bool ignored##unique = true; \
if( condition ) { \
ignored##unique = call_error_handler( context, ssphp, /*warning*/true, ## __VA_ARGS__ ); \
ignored##unique = call_error_handler( context, ssphp, /*warning*/1, ## __VA_ARGS__ ); \
} \
if( !ignored##unique )

Expand All @@ -2014,7 +2014,7 @@ inline bool is_truncated_warning( _In_ SQLCHAR* state )

#define CHECK_SQL_WARNING( result, context, ... ) \
if( result == SQL_SUCCESS_WITH_INFO ) { \
(void)call_error_handler( context, 0, /*warning*/ true, ## __VA_ARGS__ ); \
(void)call_error_handler( context, 0, /*warning*/1, ## __VA_ARGS__ ); \
}

#define CHECK_CUSTOM_WARNING_AS_ERROR( condition, context, ssphp, ... ) \
Expand All @@ -2027,16 +2027,16 @@ inline bool is_truncated_warning( _In_ SQLCHAR* state )
SQLSRV_ASSERT( result != SQL_INVALID_HANDLE, "Invalid handle returned." ); \
bool ignored = true; \
if( result == SQL_ERROR ) { \
ignored = call_error_handler( context, SQLSRV_ERROR_ODBC, false, ##__VA_ARGS__ ); \
ignored = call_error_handler( context, SQLSRV_ERROR_ODBC, 0, ##__VA_ARGS__ ); \
} \
else if( result == SQL_SUCCESS_WITH_INFO ) { \
ignored = call_error_handler( context, SQLSRV_ERROR_ODBC, true, ##__VA_ARGS__ ); \
ignored = call_error_handler( context, SQLSRV_ERROR_ODBC, 1, ##__VA_ARGS__ ); \
} \
if( !ignored )

// throw an exception after it has been hooked into the custom error handler
#define THROW_CORE_ERROR( ctx, custom, ... ) \
(void)call_error_handler( ctx, custom, /*warning*/ false, ## __VA_ARGS__ ); \
(void)call_error_handler( ctx, custom, /*warning*/0, ## __VA_ARGS__ ); \
throw core::CoreException();

//*********************************************************************************************************************************
Expand Down
36 changes: 18 additions & 18 deletions source/shared/core_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void default_sql_type( _Inout_ sqlsrv_stmt* stmt, _In_opt_ SQLULEN paramno, _In_
_Out_ SQLSMALLINT& sql_type );
void col_cache_dtor( _Inout_ zval* data_z );
void field_cache_dtor( _Inout_ zval* data_z );
int round_up_decimal_numbers(_Inout_ char* buffer, _In_ short decimal_pos, _In_ short decimals_places, _In_ short offset, _In_ short lastpos);
int round_up_decimal_numbers(_Inout_ char* buffer, _In_ int decimal_pos, _In_ int decimals_places, _In_ int offset, _In_ int lastpos);
void format_decimal_numbers(_In_ SQLSMALLINT decimals_places, _In_ SQLSMALLINT field_scale, _Inout_updates_bytes_(*field_len) char*& field_value, _Inout_ SQLLEN* field_len);
void finalize_output_parameters( _Inout_ sqlsrv_stmt* stmt, _In_opt_ bool exception_thrown = false );
void get_field_as_string( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT field_index, _Inout_ sqlsrv_phptype sqlsrv_php_type,
Expand Down Expand Up @@ -2355,8 +2355,8 @@ void format_decimal_numbers(_In_ SQLSMALLINT decimals_places, _In_ SQLSMALLINT f
}

char buffer[50] = " "; // A buffer with two blank spaces, as leeway
short offset = 1 + is_negative;
short src_length = strlen(src);
int offset = 1 + is_negative;
int src_length = strlen(src);

if (add_leading_zero) {
buffer[offset++] = '0';
Expand All @@ -2368,7 +2368,7 @@ void format_decimal_numbers(_In_ SQLSMALLINT decimals_places, _In_ SQLSMALLINT f

// If no need to adjust decimal places, skip formatting
if (decimals_places != NO_CHANGE_DECIMAL_PLACES) {
short num_decimals = src_length - (pt - src) - 1;
int num_decimals = src_length - (pt - src) - 1;

if (num_decimals > scale) {
last_pos = round_up_decimal_numbers(buffer, (pt - src) + offset, scale, offset, last_pos);
Expand All @@ -2385,7 +2385,7 @@ void format_decimal_numbers(_In_ SQLSMALLINT decimals_places, _In_ SQLSMALLINT f
buffer[--offset] = '-';
}

short len = last_pos - offset;
int len = last_pos - offset;
memcpy_s(field_value, len, buffer + offset, len);
field_value[len] = '\0';
*field_len = len;
Expand Down Expand Up @@ -3007,7 +3007,7 @@ void sqlsrv_stream_dtor( _Inout_ zval* data )
void adjustDecimalPrecision(_Inout_ zval* param_z, _In_ SQLSMALLINT decimal_digits)
{
char* value = Z_STRVAL_P(param_z);
short value_len = Z_STRLEN_P(param_z);
int value_len = Z_STRLEN_P(param_z);

// If the length is greater than maxDecimalStrLen, do not convert the string
// 6 is derived from: 1 for the decimal point; 1 for sign of the number; 1 for 'e' or 'E' (scientific notation);
Expand All @@ -3023,7 +3023,7 @@ void adjustDecimalPrecision(_Inout_ zval* param_z, _In_ SQLSMALLINT decimal_digi
try {
d = std::stold(std::string(value), &idx);
}
catch (const std::logic_error& err) {
catch (const std::logic_error& ) {
return; // invalid input caused the conversion to throw an exception
}
if (idx < value_len) {
Expand All @@ -3047,15 +3047,15 @@ void adjustDecimalPrecision(_Inout_ zval* param_z, _In_ SQLSMALLINT decimal_digi
char *pt = strchr(src, DECIMAL_POINT);

char buffer[50] = " "; // A buffer with 2 blank spaces, as leeway
short offset = 1 + is_negative; // The position to start copying the original numerical value
int offset = 1 + is_negative; // The position to start copying the original numerical value

if (exp == NULL) {
if (pt == NULL) {
return; // decimal point not found
}

short src_length = strlen(src);
short num_decimals = src_length - (pt - src) - 1;
int src_length = strlen(src);
int num_decimals = src_length - (pt - src) - 1;
if (num_decimals <= decimal_digits) {
return; // no need to adjust number of decimals
}
Expand All @@ -3069,10 +3069,10 @@ void adjustDecimalPrecision(_Inout_ zval* param_z, _In_ SQLSMALLINT decimal_digi
return; // Out of range, so let the server handle this
}

short num_decimals = 0;
int num_decimals = 0;
if (power == 0) {
// Simply chop off the exp part
short length = (exp - src);
int length = (exp - src);
memcpy_s(buffer + offset, length, src, length);

if (pt != NULL) {
Expand All @@ -3083,7 +3083,7 @@ void adjustDecimalPrecision(_Inout_ zval* param_z, _In_ SQLSMALLINT decimal_digi
}
}
} else {
short oldpos = 0;
int oldpos = 0;
if (pt == NULL) {
oldpos = exp - src; // Decimal point not found, use the exp sign
}
Expand All @@ -3096,7 +3096,7 @@ void adjustDecimalPrecision(_Inout_ zval* param_z, _In_ SQLSMALLINT decimal_digi
}

// Derive the new position for the decimal point in the buffer
short newpos = oldpos + power;
int newpos = oldpos + power;
if (power > 0) {
newpos = newpos + offset;
if (num_decimals == 0) {
Expand Down Expand Up @@ -3125,8 +3125,8 @@ void adjustDecimalPrecision(_Inout_ zval* param_z, _In_ SQLSMALLINT decimal_digi

// Start copying the content to the buffer until the exp sign or one more digit after decimal_digits
char *p = src;
short idx = offset;
short lastpos = newpos + decimal_digits + 1;
int idx = offset;
int lastpos = newpos + decimal_digits + 1;
while (p != exp && idx <= lastpos) {
if (*p == DECIMAL_POINT) {
p++;
Expand Down Expand Up @@ -3156,14 +3156,14 @@ void adjustDecimalPrecision(_Inout_ zval* param_z, _In_ SQLSMALLINT decimal_digi
ZVAL_NEW_STR(param_z, zstr);
}

int round_up_decimal_numbers(_Inout_ char* buffer, _In_ short decimal_pos, _In_ short num_decimals, _In_ short offset, _In_ short lastpos)
int round_up_decimal_numbers(_Inout_ char* buffer, _In_ int decimal_pos, _In_ int num_decimals, _In_ int offset, _In_ int lastpos)
{
// This helper method assumes the 'buffer' has some extra blank spaces at the beginning without the minus '-' sign.
// We want the rounding to be consistent with php number_format(), http://php.net/manual/en/function.number-format.php
// as well as SQL Server Management studio, such that the least significant digit will be rounded up if it is
// followed by 5 or above.

short pos = decimal_pos + num_decimals + 1;
int pos = decimal_pos + num_decimals + 1;
if (pos < lastpos) {
short n = buffer[pos] - '0';
if (n >= 5) {
Expand Down
Loading