iliaa Fri Feb 23 00:37:36 2007 UTC
Modified files: (Branch: PHP_5_2)
/php-src/ext/sybase php_sybase_db.c
/php-src/ext/standard dl.c
/php-src/ext/sybase_ct php_sybase_ct.c
/php-src/ext/pgsql pgsql.c
Log:
Simplify code by converting emalloc() + sprintf() to spprintf()
http://cvs.php.net/viewvc.cgi/php-src/ext/sybase/php_sybase_db.c?r1=1.66.2.5.2.1&r2=1.66.2.5.2.2&diff_format=u
Index: php-src/ext/sybase/php_sybase_db.c
diff -u php-src/ext/sybase/php_sybase_db.c:1.66.2.5.2.1
php-src/ext/sybase/php_sybase_db.c:1.66.2.5.2.2
--- php-src/ext/sybase/php_sybase_db.c:1.66.2.5.2.1 Mon Jan 1 09:36:09 2007
+++ php-src/ext/sybase/php_sybase_db.c Fri Feb 23 00:37:35 2007
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_sybase_db.c,v 1.66.2.5.2.1 2007/01/01 09:36:09 sebastian Exp $ */
+/* $Id: php_sybase_db.c,v 1.66.2.5.2.2 2007/02/23 00:37:35 iliaa Exp $ */
#ifdef HAVE_CONFIG_H
@@ -327,9 +327,7 @@
}
convert_to_string_ex(yyhost);
host = Z_STRVAL_PP(yyhost);
- hashed_details_length = Z_STRLEN_PP(yyhost)+6+5;
- hashed_details = (char *)
emalloc(hashed_details_length+1);
- sprintf(hashed_details,"sybase_%s____",
Z_STRVAL_PP(yyhost));
+ hashed_details_length =
spprintf(&hashed_details, 0, "sybase_%s____", Z_STRVAL_PP(yyhost));
}
break;
case 2: {
@@ -342,9 +340,7 @@
convert_to_string_ex(yyuser);
host = Z_STRVAL_PP(yyhost);
user = Z_STRVAL_PP(yyuser);
- hashed_details_length =
Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+6+5;
- hashed_details = (char *)
emalloc(hashed_details_length+1);
-
sprintf(hashed_details,"sybase_%s_%s___",Z_STRVAL_PP(yyhost),Z_STRVAL_PP(yyuser));
+ hashed_details_length =
sprintf(&hashed_details, 0, "sybase_%s_%s___", Z_STRVAL_PP(yyhost),
Z_STRVAL_PP(yyuser));
}
break;
case 3: {
@@ -359,9 +355,7 @@
host = Z_STRVAL_PP(yyhost);
user = Z_STRVAL_PP(yyuser);
passwd = Z_STRVAL_PP(yypasswd);
- hashed_details_length =
Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+Z_STRLEN_PP(yypasswd)+6+5;
- hashed_details = (char *)
emalloc(hashed_details_length+1);
-
sprintf(hashed_details,"sybase_%s_%s_%s__",Z_STRVAL_PP(yyhost),Z_STRVAL_PP(yyuser),Z_STRVAL_PP(yypasswd));
/* SAFE */
+ spprintf(&hashed_details, 0,
"sybase_%s_%s_%s__", Z_STRVAL_PP(yyhost), Z_STRVAL_PP(yyuser),
Z_STRVAL_PP(yypasswd));
}
break;
case 4: {
@@ -378,9 +372,7 @@
user = Z_STRVAL_PP(yyuser);
passwd = Z_STRVAL_PP(yypasswd);
charset = Z_STRVAL_PP(yycharset);
- hashed_details_length =
Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+Z_STRLEN_PP(yypasswd)+Z_STRLEN_PP(yycharset)+6+5;
- hashed_details = (char *)
emalloc(hashed_details_length+1);
-
sprintf(hashed_details,"sybase_%s_%s_%s_%s_",Z_STRVAL_PP(yyhost),Z_STRVAL_PP(yyuser),Z_STRVAL_PP(yypasswd),Z_STRVAL_PP(yycharset));
/* SAFE */
+ hashed_details_length =
spprintf(&hashed_details, 0, "sybase_%s_%s_%s_%s_", Z_STRVAL_PP(yyhost),
Z_STRVAL_PP(yyuser), Z_STRVAL_PP(yypasswd), Z_STRVAL_PP(yycharset));
}
break;
case 5: {
@@ -399,9 +391,7 @@
passwd = Z_STRVAL_PP(yypasswd);
charset = Z_STRVAL_PP(yycharset);
appname = Z_STRVAL_PP(yyappname);
- hashed_details_length =
Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+Z_STRLEN_PP(yypasswd)+Z_STRLEN_PP(yycharset)+Z_STRLEN_PP(yyappname)+6+5;
- hashed_details = (char *)
emalloc(hashed_details_length+1);
-
sprintf(hashed_details,"sybase_%s_%s_%s_%s_%s",Z_STRVAL_PP(yyhost),Z_STRVAL_PP(yyuser),Z_STRVAL_PP(yypasswd),Z_STRVAL_PP(yycharset),Z_STRVAL_PP(yyappname));
/* SAFE */
+ hashed_details_length =
spprintf(hashed_details, 0, "sybase_%s_%s_%s_%s_%s", Z_STRVAL_PP(yyhost),
Z_STRVAL_PP(yyuser), Z_STRVAL_PP(yypasswd), Z_STRVAL_PP(yycharset),
Z_STRVAL_PP(yyappname));
}
break;
default:
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/dl.c?r1=1.106.2.1.2.1&r2=1.106.2.1.2.2&diff_format=u
Index: php-src/ext/standard/dl.c
diff -u php-src/ext/standard/dl.c:1.106.2.1.2.1
php-src/ext/standard/dl.c:1.106.2.1.2.2
--- php-src/ext/standard/dl.c:1.106.2.1.2.1 Mon Jan 1 09:36:08 2007
+++ php-src/ext/standard/dl.c Fri Feb 23 00:37:35 2007
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dl.c,v 1.106.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */
+/* $Id: dl.c,v 1.106.2.1.2.2 2007/02/23 00:37:35 iliaa Exp $ */
#include "php.h"
#include "dl.h"
@@ -125,12 +125,10 @@
if (extension_dir && extension_dir[0]){
int extension_dir_len = strlen(extension_dir);
- libpath = emalloc(extension_dir_len+Z_STRLEN_P(file)+2);
-
if (IS_SLASH(extension_dir[extension_dir_len-1])) {
- sprintf(libpath, "%s%s", extension_dir,
Z_STRVAL_P(file)); /* SAFE */
+ spprintf(&libpath, 0, "%s%s", extension_dir,
Z_STRVAL_P(file));
} else {
- sprintf(libpath, "%s%c%s", extension_dir,
DEFAULT_SLASH, Z_STRVAL_P(file)); /* SAFE */
+ spprintf(&libpath, 0, "%s%c%s", extension_dir,
DEFAULT_SLASH, Z_STRVAL_P(file));
}
} else {
libpath = estrndup(Z_STRVAL_P(file), Z_STRLEN_P(file));
http://cvs.php.net/viewvc.cgi/php-src/ext/sybase_ct/php_sybase_ct.c?r1=1.103.2.5.2.7&r2=1.103.2.5.2.8&diff_format=u
Index: php-src/ext/sybase_ct/php_sybase_ct.c
diff -u php-src/ext/sybase_ct/php_sybase_ct.c:1.103.2.5.2.7
php-src/ext/sybase_ct/php_sybase_ct.c:1.103.2.5.2.8
--- php-src/ext/sybase_ct/php_sybase_ct.c:1.103.2.5.2.7 Mon Jan 1 09:36:09 2007
+++ php-src/ext/sybase_ct/php_sybase_ct.c Fri Feb 23 00:37:35 2007
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_sybase_ct.c,v 1.103.2.5.2.7 2007/01/01 09:36:09 sebastian Exp $ */
+/* $Id: php_sybase_ct.c,v 1.103.2.5.2.8 2007/02/23 00:37:35 iliaa Exp $ */
#ifdef HAVE_CONFIG_H
@@ -599,9 +599,7 @@
convert_to_string_ex(yyhost);
host = Z_STRVAL_PP(yyhost);
user=passwd=charset=appname=NULL;
- hashed_details_length = Z_STRLEN_PP(yyhost)+6+5;
- hashed_details = (char *)
emalloc(hashed_details_length+1);
- sprintf(hashed_details, "sybase_%s____",
Z_STRVAL_PP(yyhost));
+ hashed_details_length =
spprintf(hashed_details, 0, "sybase_%s____", Z_STRVAL_PP(yyhost));
}
break;
case 2: {
@@ -615,9 +613,7 @@
host = Z_STRVAL_PP(yyhost);
user = Z_STRVAL_PP(yyuser);
passwd=charset=appname=NULL;
- hashed_details_length =
Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+6+5;
- hashed_details = (char *)
emalloc(hashed_details_length+1);
- sprintf(hashed_details, "sybase_%s_%s___",
Z_STRVAL_PP(yyhost), Z_STRVAL_PP(yyuser));
+ hashed_details_length =
spprintf(hashed_details, 0, "sybase_%s_%s___", Z_STRVAL_PP(yyhost),
Z_STRVAL_PP(yyuser));
}
break;
case 3: {
@@ -633,9 +629,7 @@
user = Z_STRVAL_PP(yyuser);
passwd = Z_STRVAL_PP(yypasswd);
charset=appname=NULL;
- hashed_details_length =
Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+Z_STRLEN_PP(yypasswd)+6+5;
- hashed_details = (char *)
emalloc(hashed_details_length+1);
- sprintf(hashed_details, "sybase_%s_%s_%s__",
Z_STRVAL_PP(yyhost), Z_STRVAL_PP(yyuser), Z_STRVAL_PP(yypasswd));
+ hashed_details_length =
spprintf(hashed_details, 0, "sybase_%s_%s_%s__", Z_STRVAL_PP(yyhost),
Z_STRVAL_PP(yyuser), Z_STRVAL_PP(yypasswd));
}
break;
case 4: {
@@ -653,9 +647,7 @@
passwd = Z_STRVAL_PP(yypasswd);
charset = Z_STRVAL_PP(yycharset);
appname=NULL;
- hashed_details_length =
Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+Z_STRLEN_PP(yypasswd)+Z_STRLEN_PP(yycharset)+6+5;
- hashed_details = (char *)
emalloc(hashed_details_length+1);
- sprintf(hashed_details, "sybase_%s_%s_%s_%s_",
Z_STRVAL_PP(yyhost), Z_STRVAL_PP(yyuser), Z_STRVAL_PP(yypasswd),
Z_STRVAL_PP(yycharset));
+ hashed_details_length =
spprintf(hashed_details, 0, "sybase_%s_%s_%s_%s_", Z_STRVAL_PP(yyhost),
Z_STRVAL_PP(yyuser), Z_STRVAL_PP(yypasswd), Z_STRVAL_PP(yycharset));
}
break;
case 5: {
@@ -674,9 +666,7 @@
passwd = Z_STRVAL_PP(yypasswd);
charset = Z_STRVAL_PP(yycharset);
appname = Z_STRVAL_PP(yyappname);
- hashed_details_length =
Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+Z_STRLEN_PP(yypasswd)+Z_STRLEN_PP(yycharset)+Z_STRLEN_PP(yyappname)+6+5;
- hashed_details = (char *)
emalloc(hashed_details_length+1);
- sprintf(hashed_details,
"sybase_%s_%s_%s_%s_%s", Z_STRVAL_PP(yyhost), Z_STRVAL_PP(yyuser),
Z_STRVAL_PP(yypasswd), Z_STRVAL_PP(yycharset), Z_STRVAL_PP(yyappname));
+ hashed_details_length =
spprintf(hashed_details, 0, "sybase_%s_%s_%s_%s_%s", Z_STRVAL_PP(yyhost),
Z_STRVAL_PP(yyuser), Z_STRVAL_PP(yypasswd), Z_STRVAL_PP(yycharset),
Z_STRVAL_PP(yyappname));
}
break;
default:
http://cvs.php.net/viewvc.cgi/php-src/ext/pgsql/pgsql.c?r1=1.331.2.13.2.18&r2=1.331.2.13.2.19&diff_format=u
Index: php-src/ext/pgsql/pgsql.c
diff -u php-src/ext/pgsql/pgsql.c:1.331.2.13.2.18
php-src/ext/pgsql/pgsql.c:1.331.2.13.2.19
--- php-src/ext/pgsql/pgsql.c:1.331.2.13.2.18 Thu Jan 11 16:45:37 2007
+++ php-src/ext/pgsql/pgsql.c Fri Feb 23 00:37:36 2007
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pgsql.c,v 1.331.2.13.2.18 2007/01/11 16:45:37 tony2001 Exp $ */
+/* $Id: pgsql.c,v 1.331.2.13.2.19 2007/02/23 00:37:36 iliaa Exp $ */
#include <stdlib.h>
@@ -3303,7 +3303,6 @@
char *table_name, *pg_delim = NULL, *pg_null_as = NULL;
int table_name_len, pg_delim_len, pg_null_as_len;
char *query;
- char *query_template = "COPY \"\" TO STDOUT DELIMITERS ':' WITH NULL AS
''";
int id = -1;
PGconn *pgsql;
PGresult *pgsql_result;
@@ -3331,9 +3330,7 @@
pg_null_as = safe_estrdup("\\\\N");
}
- query = (char *)emalloc(strlen(query_template) + strlen(table_name) +
strlen(pg_null_as) + 1);
- sprintf(query, "COPY \"%s\" TO STDOUT DELIMITERS '%c' WITH NULL AS
'%s'",
- table_name, *pg_delim, pg_null_as);
+ spprintf(&query, 0, "COPY \"%s\" TO STDOUT DELIMITERS '%c' WITH NULL AS
'%s'", table_name, *pg_delim, pg_null_as);
while ((pgsql_result = PQgetResult(pgsql))) {
PQclear(pgsql_result);
@@ -3441,7 +3438,6 @@
int table_name_len, pg_delim_len, pg_null_as_len;
int pg_null_as_free = 0;
char *query;
- char *query_template = "COPY \"\" FROM STDIN DELIMITERS ':' WITH NULL
AS ''";
HashPosition pos;
int id = -1;
PGconn *pgsql;
@@ -3464,9 +3460,7 @@
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL
link", le_link, le_plink);
- query = (char *)emalloc(strlen(query_template) + strlen(table_name) +
strlen(pg_null_as) + 1);
- sprintf(query, "COPY \"%s\" FROM STDIN DELIMITERS '%c' WITH NULL AS
'%s'",
- table_name, *pg_delim, pg_null_as);
+ spprintf(&query, 0, "COPY \"%s\" FROM STDIN DELIMITERS '%c' WITH NULL
AS '%s'", table_name, *pg_delim, pg_null_as);
while ((pgsql_result = PQgetResult(pgsql))) {
PQclear(pgsql_result);
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php