diff options
author | Marcus Boerger <helly@php.net> | 2007-02-24 16:25:58 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2007-02-24 16:25:58 +0000 |
commit | 20a40063c51b20c1ea5f48c109b69fea3964b446 (patch) | |
tree | 24d6bf7894cc8080ff86f16eb5efef9da1cdf9c7 /ext/mysql/php_mysql.c | |
parent | 10ffce328593ddda1fb31482ec5d19ce6e02556d (diff) | |
download | php-git-20a40063c51b20c1ea5f48c109b69fea3964b446.tar.gz |
- avoid sprintf
Diffstat (limited to 'ext/mysql/php_mysql.c')
-rw-r--r-- | ext/mysql/php_mysql.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/ext/mysql/php_mysql.c b/ext/mysql/php_mysql.c index 6adb72454b..636e80ef1b 100644 --- a/ext/mysql/php_mysql.c +++ b/ext/mysql/php_mysql.c @@ -441,9 +441,9 @@ PHP_MINFO_FUNCTION(mysql) php_info_print_table_start(); php_info_print_table_header(2, "MySQL Support", "enabled"); - sprintf(buf, "%ld", MySG(num_persistent)); + snprintf(buf, sizeof(buf), "%ld", MySG(num_persistent)); php_info_print_table_row(2, "Active Persistent Links", buf); - sprintf(buf, "%ld", MySG(num_links)); + snprintf(buf, sizeof(buf), "%ld", MySG(num_links)); php_info_print_table_row(2, "Active Links", buf); php_info_print_table_row(2, "Client API version", mysql_get_client_info()); #if !defined (PHP_WIN32) && !defined (NETWARE) @@ -513,9 +513,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) } host_and_port=passwd=NULL; user=php_get_current_user(); - hashed_details_length = strlen(user)+5+3; - hashed_details = (char *) emalloc(hashed_details_length+1); - sprintf(hashed_details, "mysql__%s_", user); + hashed_details_length = spprintf(&hashed_details, 0, "mysql__%s_", user); client_flags = CLIENT_INTERACTIVE; } else { host_and_port = MySG(default_host); @@ -538,9 +536,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) client_flags ^= CLIENT_LOCAL_FILES; } - hashed_details_length = sizeof("mysql___")-1 + strlen(SAFE_STRING(host_and_port))+strlen(SAFE_STRING(user))+strlen(SAFE_STRING(passwd)); - hashed_details = (char *) emalloc(hashed_details_length+1); - sprintf(hashed_details, "mysql_%s_%s_%s", SAFE_STRING(host_and_port), SAFE_STRING(user), SAFE_STRING(passwd)); + hashed_details_length = spprintf(&hashed_details, 0, "mysql_%s_%s_%s", SAFE_STRING(host_and_port), SAFE_STRING(user), SAFE_STRING(passwd)); } /* We cannot use mysql_port anymore in windows, need to use @@ -1137,8 +1133,8 @@ static void php_mysql_do_query_general(char *query, zval **mysql_link, int link_ if (!strncasecmp("select", query, 6)){ MYSQL_ROW row; - char *newquery = (char *)emalloc(strlen(query) + 10); - sprintf ((char *)newquery, "EXPLAIN %s", query); + char *newquery; + spprintf(&newquery, 0, "EXPLAIN %s", query); mysql_real_query(&mysql->conn, newquery, strlen(newquery)); efree (newquery); if (mysql_errno(&mysql->conn)) { |