ext/odbc: various minor refactorings (#19337)

This commit is contained in:
Gina Peter Banyard 2025-07-31 23:56:27 +01:00 committed by GitHub
parent 18dee43e02
commit 2c4d4a6f18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -346,21 +346,21 @@ static void _close_odbc_pconn(zend_resource *rsrc)
/* {{{ PHP_INI_DISP(display_link_nums) */ /* {{{ PHP_INI_DISP(display_link_nums) */
static PHP_INI_DISP(display_link_nums) static PHP_INI_DISP(display_link_nums)
{ {
char *value; const zend_string *value;
if (type == PHP_INI_DISPLAY_ORIG && ini_entry->modified) { if (type == PHP_INI_DISPLAY_ORIG && ini_entry->modified) {
value = ZSTR_VAL(ini_entry->orig_value); value = ini_entry->orig_value;
} else if (ini_entry->value) { } else if (ini_entry->value) {
value = ZSTR_VAL(ini_entry->value); value = ini_entry->value;
} else { } else {
value = NULL; value = NULL;
} }
if (value) { if (value) {
if (atoi(value) == -1) { if (atoi(ZSTR_VAL(value)) == -1) {
PUTS("Unlimited"); PUTS("Unlimited");
} else { } else {
php_printf("%s", value); php_output_write(ZSTR_VAL(value), ZSTR_LEN(value));
} }
} }
} }
@ -670,7 +670,6 @@ void odbc_bindcols(odbc_result *result)
SQLSMALLINT colnamelen; /* Not used */ SQLSMALLINT colnamelen; /* Not used */
SQLLEN displaysize; SQLLEN displaysize;
SQLUSMALLINT colfieldid; SQLUSMALLINT colfieldid;
int charextraalloc;
result->values = (odbc_result_value *) safe_emalloc(sizeof(odbc_result_value), result->numcols, 0); result->values = (odbc_result_value *) safe_emalloc(sizeof(odbc_result_value), result->numcols, 0);
@ -678,7 +677,7 @@ void odbc_bindcols(odbc_result *result)
result->binmode = ODBCG(defaultbinmode); result->binmode = ODBCG(defaultbinmode);
for(i = 0; i < result->numcols; i++) { for(i = 0; i < result->numcols; i++) {
charextraalloc = 0; bool char_extra_alloc = false;
colfieldid = SQL_COLUMN_DISPLAY_SIZE; colfieldid = SQL_COLUMN_DISPLAY_SIZE;
rc = PHP_ODBC_SQLCOLATTRIBUTE(result->stmt, (SQLUSMALLINT)(i+1), PHP_ODBC_SQL_DESC_NAME, rc = PHP_ODBC_SQLCOLATTRIBUTE(result->stmt, (SQLUSMALLINT)(i+1), PHP_ODBC_SQL_DESC_NAME,
@ -716,7 +715,7 @@ void odbc_bindcols(odbc_result *result)
case SQL_WVARCHAR: case SQL_WVARCHAR:
colfieldid = SQL_DESC_OCTET_LENGTH; colfieldid = SQL_DESC_OCTET_LENGTH;
#else #else
charextraalloc = 1; char_extra_alloc = true;
#endif #endif
/* TODO: Check this is the intended behaviour */ /* TODO: Check this is the intended behaviour */
ZEND_FALLTHROUGH; ZEND_FALLTHROUGH;
@ -742,7 +741,7 @@ void odbc_bindcols(odbc_result *result)
} }
/* This is a quirk for ODBC 2.0 compatibility for broken driver implementations. /* This is a quirk for ODBC 2.0 compatibility for broken driver implementations.
*/ */
charextraalloc = 1; char_extra_alloc = true;
rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_DISPLAY_SIZE, rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_DISPLAY_SIZE,
NULL, 0, NULL, &displaysize); NULL, 0, NULL, &displaysize);
if (rc != SQL_SUCCESS) { if (rc != SQL_SUCCESS) {
@ -769,7 +768,7 @@ void odbc_bindcols(odbc_result *result)
displaysize += 3; displaysize += 3;
} }
if (charextraalloc) { if (char_extra_alloc) {
/* Since we don't know the exact # of bytes, allocate extra */ /* Since we don't know the exact # of bytes, allocate extra */
displaysize *= 4; displaysize *= 4;
} }
@ -1015,10 +1014,9 @@ PHP_FUNCTION(odbc_execute)
zval *pv_res, *tmp; zval *pv_res, *tmp;
HashTable *pv_param_ht = (HashTable *) &zend_empty_array; HashTable *pv_param_ht = (HashTable *) &zend_empty_array;
odbc_params_t *params = NULL; odbc_params_t *params = NULL;
char *filename;
SQLSMALLINT ctype; SQLSMALLINT ctype;
odbc_result *result; odbc_result *result;
int i, ne; int i;
RETCODE rc; RETCODE rc;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|h", &pv_res, odbc_result_ce, &pv_param_ht) == FAILURE) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|h", &pv_res, odbc_result_ce, &pv_param_ht) == FAILURE) {
@ -1029,8 +1027,9 @@ PHP_FUNCTION(odbc_execute)
CHECK_ODBC_RESULT(result); CHECK_ODBC_RESULT(result);
if (result->numparams > 0) { if (result->numparams > 0) {
if ((ne = zend_hash_num_elements(pv_param_ht)) < result->numparams) { uint32_t ne = zend_hash_num_elements(pv_param_ht);
php_error_docref(NULL, E_WARNING, "Not enough parameters (%d should be %d) given", ne, result->numparams); if (ne < result->numparams) {
php_error_docref(NULL, E_WARNING, "Not enough parameters (%" PRIu32 " should be %d) given", ne, result->numparams);
RETURN_FALSE; RETURN_FALSE;
} }
@ -1067,7 +1066,7 @@ PHP_FUNCTION(odbc_execute)
odbc_release_params(result, params); odbc_release_params(result, params);
RETURN_FALSE; RETURN_FALSE;
} }
filename = estrndup(&ZSTR_VAL(tmpstr)[1], ZSTR_LEN(tmpstr) - 2); char *filename = estrndup(&ZSTR_VAL(tmpstr)[1], ZSTR_LEN(tmpstr) - 2);
/* Check the basedir */ /* Check the basedir */
if (php_check_open_basedir(filename)) { if (php_check_open_basedir(filename)) {
@ -2185,8 +2184,7 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, bool
int direct = 0; int direct = 0;
SQLCHAR dsnbuf[1024]; SQLCHAR dsnbuf[1024];
short dsnbuflen; short dsnbuflen;
char *ldb = 0; char *ldb = NULL;
int ldb_len = 0;
/* a connection string may have = but not ; - i.e. "DSN=PHP" */ /* a connection string may have = but not ; - i.e. "DSN=PHP" */
if (strstr((char*)db, "=")) { if (strstr((char*)db, "=")) {
@ -2248,7 +2246,7 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, bool
efree(pwd_quoted); efree(pwd_quoted);
} }
} else { } else {
ldb_len = strlen(db)+1; size_t ldb_len = strlen(db)+1;
ldb = (char*) emalloc(ldb_len); ldb = (char*) emalloc(ldb_len);
memcpy(ldb, db, ldb_len); memcpy(ldb, db, ldb_len);
} }