Skip to content

ext/odbc: various minor refactorings #19337

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

Merged
merged 1 commit into from
Jul 31, 2025
Merged
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
34 changes: 16 additions & 18 deletions ext/odbc/php_odbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,21 @@ static void _close_odbc_pconn(zend_resource *rsrc)
/* {{{ 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) {
value = ZSTR_VAL(ini_entry->orig_value);
value = ini_entry->orig_value;
} else if (ini_entry->value) {
value = ZSTR_VAL(ini_entry->value);
value = ini_entry->value;
} else {
value = NULL;
}

if (value) {
if (atoi(value) == -1) {
if (atoi(ZSTR_VAL(value)) == -1) {
PUTS("Unlimited");
} else {
php_printf("%s", value);
php_output_write(ZSTR_VAL(value), ZSTR_LEN(value));
}
}
}
Expand Down Expand Up @@ -670,15 +670,14 @@ void odbc_bindcols(odbc_result *result)
SQLSMALLINT colnamelen; /* Not used */
SQLLEN displaysize;
SQLUSMALLINT colfieldid;
int charextraalloc;

result->values = (odbc_result_value *) safe_emalloc(sizeof(odbc_result_value), result->numcols, 0);

result->longreadlen = ODBCG(defaultlrl);
result->binmode = ODBCG(defaultbinmode);

for(i = 0; i < result->numcols; i++) {
charextraalloc = 0;
bool char_extra_alloc = false;
colfieldid = SQL_COLUMN_DISPLAY_SIZE;

rc = PHP_ODBC_SQLCOLATTRIBUTE(result->stmt, (SQLUSMALLINT)(i+1), PHP_ODBC_SQL_DESC_NAME,
Expand Down Expand Up @@ -716,7 +715,7 @@ void odbc_bindcols(odbc_result *result)
case SQL_WVARCHAR:
colfieldid = SQL_DESC_OCTET_LENGTH;
#else
charextraalloc = 1;
char_extra_alloc = true;
#endif
/* TODO: Check this is the intended behaviour */
ZEND_FALLTHROUGH;
Expand All @@ -742,7 +741,7 @@ void odbc_bindcols(odbc_result *result)
}
/* 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,
NULL, 0, NULL, &displaysize);
if (rc != SQL_SUCCESS) {
Expand All @@ -769,7 +768,7 @@ void odbc_bindcols(odbc_result *result)
displaysize += 3;
}

if (charextraalloc) {
if (char_extra_alloc) {
/* Since we don't know the exact # of bytes, allocate extra */
displaysize *= 4;
}
Expand Down Expand Up @@ -1015,10 +1014,9 @@ PHP_FUNCTION(odbc_execute)
zval *pv_res, *tmp;
HashTable *pv_param_ht = (HashTable *) &zend_empty_array;
odbc_params_t *params = NULL;
char *filename;
SQLSMALLINT ctype;
odbc_result *result;
int i, ne;
int i;
RETCODE rc;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|h", &pv_res, odbc_result_ce, &pv_param_ht) == FAILURE) {
Expand All @@ -1029,8 +1027,9 @@ PHP_FUNCTION(odbc_execute)
CHECK_ODBC_RESULT(result);

if (result->numparams > 0) {
if ((ne = zend_hash_num_elements(pv_param_ht)) < result->numparams) {
php_error_docref(NULL, E_WARNING, "Not enough parameters (%d should be %d) given", ne, result->numparams);
uint32_t ne = zend_hash_num_elements(pv_param_ht);
if (ne < result->numparams) {
php_error_docref(NULL, E_WARNING, "Not enough parameters (%" PRIu32 " should be %d) given", ne, result->numparams);
RETURN_FALSE;
}

Expand Down Expand Up @@ -1067,7 +1066,7 @@ PHP_FUNCTION(odbc_execute)
odbc_release_params(result, params);
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 */
if (php_check_open_basedir(filename)) {
Expand Down Expand Up @@ -2185,8 +2184,7 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, bool
int direct = 0;
SQLCHAR dsnbuf[1024];
short dsnbuflen;
char *ldb = 0;
int ldb_len = 0;
char *ldb = NULL;

/* a connection string may have = but not ; - i.e. "DSN=PHP" */
if (strstr((char*)db, "=")) {
Expand Down Expand Up @@ -2248,7 +2246,7 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, bool
efree(pwd_quoted);
}
} else {
ldb_len = strlen(db)+1;
size_t ldb_len = strlen(db)+1;
ldb = (char*) emalloc(ldb_len);
memcpy(ldb, db, ldb_len);
}
Expand Down