Skip to content

Commit dfe6aea

Browse files
committed
size_t cleanup for PDO
1 parent 5845f2c commit dfe6aea

File tree

12 files changed

+72
-68
lines changed

12 files changed

+72
-68
lines changed

UPGRADING.INTERNALS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ PHP 7.0 INTERNALS UPGRADE NOTES
1616
o. Updated final class modifier
1717
p. TSRM changes
1818
q. gc_collect_cycles() is now hookable
19+
r. PDO uses size_t for lengths
1920

2021
2. Build system changes
2122
a. Unix build system changes
@@ -176,6 +177,9 @@ PHP 7.0 INTERNALS UPGRADE NOTES
176177
implementation has been renamed to zend_gc_collect_cycles(), and is
177178
exported with ZEND_API.
178179

180+
r. In accordance with general use of size_t as string length, all PDO API
181+
functions now use size_t for string length.
182+
179183

180184
========================
181185
2. Build system changes

ext/pdo/pdo_dbh.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,9 +962,9 @@ static PHP_METHOD(PDO, lastInsertId)
962962
pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support lastInsertId()");
963963
RETURN_FALSE;
964964
} else {
965-
int id_len;
965+
size_t id_len;
966966
char *id;
967-
id = dbh->methods->last_id(dbh, name, (unsigned int *)&id_len);
967+
id = dbh->methods->last_id(dbh, name, &id_len);
968968
if (!id) {
969969
PDO_HANDLE_DBH_ERR();
970970
RETURN_FALSE;
@@ -1136,7 +1136,7 @@ static PHP_METHOD(PDO, quote)
11361136
size_t str_len;
11371137
zend_long paramtype = PDO_PARAM_STR;
11381138
char *qstr;
1139-
int qlen;
1139+
size_t qlen;
11401140

11411141
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &str, &str_len, &paramtype)) {
11421142
RETURN_FALSE;

ext/pdo/pdo_sql_parser.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ static int scan(Scanner *s)
407407
struct placeholder {
408408
char *pos;
409409
char *quoted; /* quoted value */
410-
int len;
410+
size_t len;
411411
int bindno;
412-
int qlen; /* quoted length of value */
412+
size_t qlen; /* quoted length of value */
413413
int freeq;
414414
struct placeholder *next;
415415
};
@@ -418,15 +418,15 @@ static void free_param_name(zval *el) {
418418
efree(Z_PTR_P(el));
419419
}
420420

421-
PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len,
422-
char **outquery, int *outquery_len)
421+
PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, size_t inquery_len,
422+
char **outquery, size_t *outquery_len)
423423
{
424424
Scanner s;
425425
char *ptr, *newbuffer;
426426
int t;
427427
int bindno = 0;
428428
int ret = 0;
429-
int newbuffer_len;
429+
size_t newbuffer_len;
430430
HashTable *params;
431431
struct pdo_bound_param_data *param;
432432
int query_type = PDO_PLACEHOLDER_NONE;

ext/pdo/php_pdo_driver.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ static inline char *pdo_attr_strval(zval *options, enum pdo_attribute_type optio
219219
/* This structure is registered with PDO when a PDO driver extension is
220220
* initialized */
221221
typedef struct {
222-
const char *driver_name;
223-
zend_ulong driver_name_len;
222+
const char *driver_name;
223+
size_t driver_name_len;
224224
zend_ulong api_version; /* needs to be compatible with PDO */
225225

226226
#define PDO_DRIVER_HEADER(name) \
@@ -244,13 +244,13 @@ typedef struct {
244244
typedef int (*pdo_dbh_close_func)(pdo_dbh_t *dbh);
245245

246246
/* prepare a statement and stash driver specific portion into stmt */
247-
typedef int (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, const char *sql, zend_long sql_len, pdo_stmt_t *stmt, zval *driver_options);
247+
typedef int (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, const char *sql, size_t sql_len, pdo_stmt_t *stmt, zval *driver_options);
248248

249249
/* execute a statement (that does not return a result set) */
250-
typedef zend_long (*pdo_dbh_do_func)(pdo_dbh_t *dbh, const char *sql, zend_long sql_len);
250+
typedef zend_long (*pdo_dbh_do_func)(pdo_dbh_t *dbh, const char *sql, size_t sql_len);
251251

252252
/* quote a string */
253-
typedef int (*pdo_dbh_quote_func)(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype);
253+
typedef int (*pdo_dbh_quote_func)(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype);
254254

255255
/* transaction related */
256256
typedef int (*pdo_dbh_txn_func)(pdo_dbh_t *dbh);
@@ -260,7 +260,7 @@ typedef int (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val);
260260

261261
/* return last insert id. NULL indicates error condition, otherwise, the return value
262262
* MUST be an emalloc'd NULL terminated string. */
263-
typedef char *(*pdo_dbh_last_id_func)(pdo_dbh_t *dbh, const char *name, unsigned int *len);
263+
typedef char *(*pdo_dbh_last_id_func)(pdo_dbh_t *dbh, const char *name, size_t *len);
264264

265265
/* fetch error information. if stmt is not null, fetch information pertaining
266266
* to the statement, otherwise fetch global error information. The driver
@@ -341,7 +341,7 @@ typedef int (*pdo_stmt_describe_col_func)(pdo_stmt_t *stmt, int colno);
341341
* If the driver sets caller_frees, ptr should point to emalloc'd memory
342342
* and PDO will free it as soon as it is done using it.
343343
*/
344-
typedef int (*pdo_stmt_get_col_data_func)(pdo_stmt_t *stmt, int colno, char **ptr, zend_ulong *len, int *caller_frees);
344+
typedef int (*pdo_stmt_get_col_data_func)(pdo_stmt_t *stmt, int colno, char **ptr, size_t *len, int *caller_frees);
345345

346346
/* hook for bound params */
347347
enum pdo_param_event {
@@ -469,7 +469,7 @@ struct _pdo_dbh_t {
469469

470470
/* data source string used to open this handle */
471471
const char *data_source;
472-
zend_ulong data_source_len;
472+
size_t data_source_len;
473473

474474
/* the global error code. */
475475
pdo_error_type error_code;
@@ -480,7 +480,7 @@ struct _pdo_dbh_t {
480480

481481
/* persistent hash key associated with this handle */
482482
const char *persistent_id;
483-
int persistent_id_len;
483+
size_t persistent_id_len;
484484
unsigned int refcount;
485485

486486
/* driver specific "class" methods for the dbh and stmt */
@@ -528,10 +528,10 @@ static inline pdo_dbh_object_t *php_pdo_dbh_fetch_object(zend_object *obj) {
528528
/* describes a column */
529529
struct pdo_column_data {
530530
char *name;
531-
zend_ulong maxlen;
531+
size_t maxlen;
532532
zend_ulong precision;
533533
enum pdo_param_type param_type;
534-
int namelen;
534+
size_t namelen;
535535

536536
/* don't touch this unless your name is dbdo */
537537
void *dbdo_data;
@@ -598,11 +598,11 @@ struct _pdo_stmt_t {
598598

599599
/* used to hold the statement's current query */
600600
char *query_string;
601-
int query_stringlen;
601+
size_t query_stringlen;
602602

603603
/* the copy of the query with expanded binds ONLY for emulated-prepare drivers */
604604
char *active_query_string;
605-
int active_query_stringlen;
605+
size_t active_query_stringlen;
606606

607607
/* the cursor specific error code. */
608608
pdo_error_type error_code;
@@ -678,8 +678,8 @@ PDO_API int php_pdo_parse_data_source(const char *data_source,
678678
PDO_API zend_class_entry *php_pdo_get_dbh_ce(void);
679679
PDO_API zend_class_entry *php_pdo_get_exception(void);
680680

681-
PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len,
682-
char **outquery, int *outquery_len);
681+
PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, size_t inquery_len,
682+
char **outquery, size_t *outquery_len);
683683

684684
PDO_API void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt,
685685
const char *sqlstate, const char *supp);

ext/pdo_dblib/dblib_driver.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static int dblib_handle_closer(pdo_dbh_t *dbh)
9292
return 0;
9393
}
9494

95-
static int dblib_handle_preparer(pdo_dbh_t *dbh, const char *sql, zend_long sql_len, pdo_stmt_t *stmt, zval *driver_options)
95+
static int dblib_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len, pdo_stmt_t *stmt, zval *driver_options)
9696
{
9797
pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
9898
pdo_dblib_stmt *S = ecalloc(1, sizeof(*S));
@@ -106,7 +106,7 @@ static int dblib_handle_preparer(pdo_dbh_t *dbh, const char *sql, zend_long sql_
106106
return 1;
107107
}
108108

109-
static zend_long dblib_handle_doer(pdo_dbh_t *dbh, const char *sql, zend_long sql_len)
109+
static zend_long dblib_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len)
110110
{
111111
pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
112112
RETCODE ret, resret;
@@ -142,7 +142,7 @@ static zend_long dblib_handle_doer(pdo_dbh_t *dbh, const char *sql, zend_long sq
142142
return DBCOUNT(H->link);
143143
}
144144

145-
static int dblib_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype)
145+
static int dblib_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype)
146146
{
147147

148148
int useBinaryEncoding = 0;
@@ -230,7 +230,7 @@ static int dblib_handle_rollback(pdo_dbh_t *dbh)
230230
return pdo_dblib_transaction_cmd("ROLLBACK TRANSACTION", dbh);
231231
}
232232

233-
char *dblib_handle_last_id(pdo_dbh_t *dbh, const char *name, unsigned int *len)
233+
char *dblib_handle_last_id(pdo_dbh_t *dbh, const char *name, size_t *len)
234234
{
235235
pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
236236

ext/pdo_firebird/firebird_driver.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "php_pdo_firebird.h"
3232
#include "php_pdo_firebird_int.h"
3333

34-
static int firebird_alloc_prepare_stmt(pdo_dbh_t*, const char*, zend_long, XSQLDA*, isc_stmt_handle*,
34+
static int firebird_alloc_prepare_stmt(pdo_dbh_t*, const char*, size_t, XSQLDA*, isc_stmt_handle*,
3535
HashTable*);
3636

3737
/* map driver specific error message to PDO error */
@@ -130,7 +130,7 @@ static int firebird_handle_closer(pdo_dbh_t *dbh) /* {{{ */
130130
/* }}} */
131131

132132
/* called by PDO to prepare an SQL query */
133-
static int firebird_handle_preparer(pdo_dbh_t *dbh, const char *sql, zend_long sql_len, /* {{{ */
133+
static int firebird_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len, /* {{{ */
134134
pdo_stmt_t *stmt, zval *driver_options)
135135
{
136136
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
@@ -216,7 +216,7 @@ static int firebird_handle_preparer(pdo_dbh_t *dbh, const char *sql, zend_long s
216216
/* }}} */
217217

218218
/* called by PDO to execute a statement that doesn't produce a result set */
219-
static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const char *sql, zend_long sql_len) /* {{{ */
219+
static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len) /* {{{ */
220220
{
221221
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
222222
isc_stmt_handle stmt = NULL;
@@ -270,8 +270,8 @@ static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const char *sql, zend_long
270270
/* }}} */
271271

272272
/* called by the PDO SQL parser to add quotes to values that are copied into SQL */
273-
static int firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, /* {{{ */
274-
char **quoted, int *quotedlen, enum pdo_param_type paramtype)
273+
static int firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, /* {{{ */
274+
char **quoted, size_t *quotedlen, enum pdo_param_type paramtype)
275275
{
276276
int qcount = 0;
277277
char const *co, *l, *r;
@@ -389,7 +389,7 @@ static int firebird_handle_rollback(pdo_dbh_t *dbh) /* {{{ */
389389
/* }}} */
390390

391391
/* used by prepare and exec to allocate a statement handle and prepare the SQL */
392-
static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, zend_long sql_len, /* {{{ */
392+
static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, size_t sql_len, /* {{{ */
393393
XSQLDA *out_sqlda, isc_stmt_handle *s, HashTable *named_params)
394394
{
395395
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;

ext/pdo_mysql/mysql_driver.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,18 @@ static int mysql_handle_closer(pdo_dbh_t *dbh)
161161
/* }}} */
162162

163163
/* {{{ mysql_handle_preparer */
164-
static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, zend_long sql_len, pdo_stmt_t *stmt, zval *driver_options)
164+
static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len, pdo_stmt_t *stmt, zval *driver_options)
165165
{
166166
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
167167
pdo_mysql_stmt *S = ecalloc(1, sizeof(pdo_mysql_stmt));
168168
char *nsql = NULL;
169-
int nsql_len = 0;
169+
size_t nsql_len = 0;
170170
int ret;
171171
int server_version;
172172

173173
PDO_DBG_ENTER("mysql_handle_preparer");
174174
PDO_DBG_INF_FMT("dbh=%p", dbh);
175-
PDO_DBG_INF_FMT("sql=%.*s", sql_len, sql);
175+
PDO_DBG_INF_FMT("sql=%.*s", (int)sql_len, sql);
176176

177177
S->H = H;
178178
stmt->driver_data = S;
@@ -253,12 +253,12 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, zend_long sql_
253253
/* }}} */
254254

255255
/* {{{ mysql_handle_doer */
256-
static zend_long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, zend_long sql_len)
256+
static zend_long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len)
257257
{
258258
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
259259
PDO_DBG_ENTER("mysql_handle_doer");
260260
PDO_DBG_INF_FMT("dbh=%p", dbh);
261-
PDO_DBG_INF_FMT("sql=%.*s", sql_len, sql);
261+
PDO_DBG_INF_FMT("sql=%.*s", (int)sql_len, sql);
262262

263263
if (mysql_real_query(H->server, sql, sql_len)) {
264264
pdo_mysql_error(dbh);
@@ -288,7 +288,7 @@ static zend_long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, zend_long sq
288288
/* }}} */
289289

290290
/* {{{ pdo_mysql_last_insert_id */
291-
static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned int *len)
291+
static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t *len)
292292
{
293293
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
294294
char *id = php_pdo_int64_to_str(mysql_insert_id(H->server));
@@ -299,17 +299,17 @@ static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned
299299
/* }}} */
300300

301301
/* {{{ mysql_handle_quoter */
302-
static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype )
302+
static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype )
303303
{
304304
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
305305
PDO_DBG_ENTER("mysql_handle_quoter");
306306
PDO_DBG_INF_FMT("dbh=%p", dbh);
307-
PDO_DBG_INF_FMT("unquoted=%.*s", unquotedlen, unquoted);
307+
PDO_DBG_INF_FMT("unquoted=%.*s", (int)unquotedlen, unquoted);
308308
*quoted = safe_emalloc(2, unquotedlen, 3);
309309
*quotedlen = mysql_real_escape_string(H->server, *quoted + 1, unquoted, unquotedlen);
310310
(*quoted)[0] =(*quoted)[++*quotedlen] = '\'';
311311
(*quoted)[++*quotedlen] = '\0';
312-
PDO_DBG_INF_FMT("quoted=%.*s", *quotedlen, *quoted);
312+
PDO_DBG_INF_FMT("quoted=%.*s", (int)*quotedlen, *quoted);
313313
PDO_DBG_RETURN(1);
314314
}
315315
/* }}} */
@@ -559,8 +559,8 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
559559
#endif
560560
;
561561
#if defined(PDO_USE_MYSQLND)
562-
int dbname_len = 0;
563-
int password_len = 0;
562+
size_t dbname_len = 0;
563+
size_t password_len = 0;
564564
#endif
565565

566566
#ifdef CLIENT_MULTI_STATEMENTS

ext/pdo_mysql/mysql_statement.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ static int pdo_mysql_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
722722
}
723723
/* }}} */
724724

725-
static int pdo_mysql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, zend_ulong *len, int *caller_frees) /* {{{ */
725+
static int pdo_mysql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, size_t *len, int *caller_frees) /* {{{ */
726726
{
727727
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
728728

ext/pdo_oci/oci_driver.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,13 @@ static int oci_handle_closer(pdo_dbh_t *dbh) /* {{{ */
248248
}
249249
/* }}} */
250250

251-
static int oci_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, pdo_stmt_t *stmt, zval *driver_options) /* {{{ */
251+
static int oci_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len, pdo_stmt_t *stmt, zval *driver_options) /* {{{ */
252252
{
253253
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
254254
pdo_oci_stmt *S = ecalloc(1, sizeof(*S));
255255
ub4 prefetch;
256256
char *nsql = NULL;
257-
int nsql_len = 0;
257+
size_t nsql_len = 0;
258258
int ret;
259259

260260
#if HAVE_OCISTMTFETCH2
@@ -324,7 +324,7 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, pd
324324
}
325325
/* }}} */
326326

327-
static long oci_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len) /* {{{ */
327+
static long oci_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len) /* {{{ */
328328
{
329329
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
330330
OCIStmt *stmt;
@@ -368,7 +368,7 @@ static long oci_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len) /* {{
368368
}
369369
/* }}} */
370370

371-
static int oci_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype ) /* {{{ */
371+
static int oci_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype ) /* {{{ */
372372
{
373373
int qcount = 0;
374374
char const *cu, *l, *r;

0 commit comments

Comments
 (0)