php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43041 [PATCH] speedup fetches
Submitted: 2007-10-19 15:19 UTC Modified: 2007-11-22 00:20 UTC
From: andy at petdance dot com Assigned:
Status: Closed Package: PostgreSQL related
PHP Version: 5.2.4 OS: *
Private report: No CVE-ID: None
 [2007-10-19 15:19 UTC] andy at petdance dot com
Description:
------------
Not a bug at all.  Just was looking at the code for the Postgres fetching, and there are a couple of places where it's redundantly checking for NULLness on a pointer.  This patch fixes it.



Reproduce code:
---------------
--- ext/pgsql/pgsql-old.c	2007-10-19 10:03:42.166485760 -0500
+++ ext/pgsql/pgsql.c	2007-10-19 10:08:29.289836376 -0500
@@ -1992,7 +1992,6 @@
 	int             i, num_fields, pgsql_row, use_row;
 	long            row = -1;
 	char            *element, *field_name;
-	uint            element_len;
 	zval            *ctor_params = NULL;
 	zend_class_entry *ce = NULL;
 
@@ -2064,11 +2063,11 @@
 			}
 		} else {
 			element = PQgetvalue(pgsql_result, pgsql_row, i);
-			element_len = (element ? strlen(element) : 0);
 			if (element) {
 				char *data;
 				int data_len;
 				int should_copy=0;
+				const uint element_len = strlen(element);
 
 				if (PG(magic_quotes_runtime)) {
 					data = php_addslashes(element, element_len, &data_len, 0 TSRMLS_CC);
@@ -5712,7 +5711,7 @@
 {
 	zval *row;
 	char *field_name, *element, *data;
-	size_t num_fields, element_len, data_len;
+	size_t num_fields;
 	int pg_numrows, pg_row;
 	uint i;
 	assert(Z_TYPE_P(ret_array) == IS_ARRAY);
@@ -5730,8 +5729,9 @@
 				add_assoc_null(row, field_name);
 			} else {
 				element = PQgetvalue(pg_result, pg_row, i);
-				element_len = (element ? strlen(element) : 0);
 				if (element) {
+					const size_t element_len = strlen(element);
+					size_t data_len;
 					if (PG(magic_quotes_runtime)) {
 						data = php_addslashes(element, element_len, &data_len, 0 TSRMLS_CC);
 					} else {



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-22 00:20 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 07:01:31 2024 UTC