Skip to content

Commit 2c4d4a6

Browse files
authored
ext/odbc: various minor refactorings (#19337)
1 parent 18dee43 commit 2c4d4a6

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

ext/odbc/php_odbc.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,21 @@ static void _close_odbc_pconn(zend_resource *rsrc)
346346
/* {{{ PHP_INI_DISP(display_link_nums) */
347347
static PHP_INI_DISP(display_link_nums)
348348
{
349-
char *value;
349+
const zend_string *value;
350350

351351
if (type == PHP_INI_DISPLAY_ORIG && ini_entry->modified) {
352-
value = ZSTR_VAL(ini_entry->orig_value);
352+
value = ini_entry->orig_value;
353353
} else if (ini_entry->value) {
354-
value = ZSTR_VAL(ini_entry->value);
354+
value = ini_entry->value;
355355
} else {
356356
value = NULL;
357357
}
358358

359359
if (value) {
360-
if (atoi(value) == -1) {
360+
if (atoi(ZSTR_VAL(value)) == -1) {
361361
PUTS("Unlimited");
362362
} else {
363-
php_printf("%s", value);
363+
php_output_write(ZSTR_VAL(value), ZSTR_LEN(value));
364364
}
365365
}
366366
}
@@ -670,15 +670,14 @@ void odbc_bindcols(odbc_result *result)
670670
SQLSMALLINT colnamelen; /* Not used */
671671
SQLLEN displaysize;
672672
SQLUSMALLINT colfieldid;
673-
int charextraalloc;
674673

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

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

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

684683
rc = PHP_ODBC_SQLCOLATTRIBUTE(result->stmt, (SQLUSMALLINT)(i+1), PHP_ODBC_SQL_DESC_NAME,
@@ -716,7 +715,7 @@ void odbc_bindcols(odbc_result *result)
716715
case SQL_WVARCHAR:
717716
colfieldid = SQL_DESC_OCTET_LENGTH;
718717
#else
719-
charextraalloc = 1;
718+
char_extra_alloc = true;
720719
#endif
721720
/* TODO: Check this is the intended behaviour */
722721
ZEND_FALLTHROUGH;
@@ -742,7 +741,7 @@ void odbc_bindcols(odbc_result *result)
742741
}
743742
/* This is a quirk for ODBC 2.0 compatibility for broken driver implementations.
744743
*/
745-
charextraalloc = 1;
744+
char_extra_alloc = true;
746745
rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_DISPLAY_SIZE,
747746
NULL, 0, NULL, &displaysize);
748747
if (rc != SQL_SUCCESS) {
@@ -769,7 +768,7 @@ void odbc_bindcols(odbc_result *result)
769768
displaysize += 3;
770769
}
771770

772-
if (charextraalloc) {
771+
if (char_extra_alloc) {
773772
/* Since we don't know the exact # of bytes, allocate extra */
774773
displaysize *= 4;
775774
}
@@ -1015,10 +1014,9 @@ PHP_FUNCTION(odbc_execute)
10151014
zval *pv_res, *tmp;
10161015
HashTable *pv_param_ht = (HashTable *) &zend_empty_array;
10171016
odbc_params_t *params = NULL;
1018-
char *filename;
10191017
SQLSMALLINT ctype;
10201018
odbc_result *result;
1021-
int i, ne;
1019+
int i;
10221020
RETCODE rc;
10231021

10241022
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)
10291027
CHECK_ODBC_RESULT(result);
10301028

10311029
if (result->numparams > 0) {
1032-
if ((ne = zend_hash_num_elements(pv_param_ht)) < result->numparams) {
1033-
php_error_docref(NULL, E_WARNING, "Not enough parameters (%d should be %d) given", ne, result->numparams);
1030+
uint32_t ne = zend_hash_num_elements(pv_param_ht);
1031+
if (ne < result->numparams) {
1032+
php_error_docref(NULL, E_WARNING, "Not enough parameters (%" PRIu32 " should be %d) given", ne, result->numparams);
10341033
RETURN_FALSE;
10351034
}
10361035

@@ -1067,7 +1066,7 @@ PHP_FUNCTION(odbc_execute)
10671066
odbc_release_params(result, params);
10681067
RETURN_FALSE;
10691068
}
1070-
filename = estrndup(&ZSTR_VAL(tmpstr)[1], ZSTR_LEN(tmpstr) - 2);
1069+
char *filename = estrndup(&ZSTR_VAL(tmpstr)[1], ZSTR_LEN(tmpstr) - 2);
10711070

10721071
/* Check the basedir */
10731072
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
21852184
int direct = 0;
21862185
SQLCHAR dsnbuf[1024];
21872186
short dsnbuflen;
2188-
char *ldb = 0;
2189-
int ldb_len = 0;
2187+
char *ldb = NULL;
21902188

21912189
/* a connection string may have = but not ; - i.e. "DSN=PHP" */
21922190
if (strstr((char*)db, "=")) {
@@ -2248,7 +2246,7 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, bool
22482246
efree(pwd_quoted);
22492247
}
22502248
} else {
2251-
ldb_len = strlen(db)+1;
2249+
size_t ldb_len = strlen(db)+1;
22522250
ldb = (char*) emalloc(ldb_len);
22532251
memcpy(ldb, db, ldb_len);
22542252
}

0 commit comments

Comments
 (0)