summaryrefslogtreecommitdiff
path: root/ext/pgsql/pgsql.c
diff options
context:
space:
mode:
authorYasuo Ohgaki <yohgaki@php.net>2002-04-04 13:54:51 +0000
committerYasuo Ohgaki <yohgaki@php.net>2002-04-04 13:54:51 +0000
commitfafea27a2d8c43c81b915e0a7eb745513c295cdc (patch)
treeef481596fcca852c81a365d43cfe9e10a1c8e4aa /ext/pgsql/pgsql.c
parentafeda571535f7db010fb5c4c67c08211e46817e6 (diff)
downloadphp-git-fafea27a2d8c43c81b915e0a7eb745513c295cdc.tar.gz
Clean up pg_escape_*()
Diffstat (limited to 'ext/pgsql/pgsql.c')
-rw-r--r--ext/pgsql/pgsql.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 934e0413b7..269a560996 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -2391,19 +2391,15 @@ PHP_FUNCTION(pg_copy_from)
PHP_FUNCTION(pg_escape_string)
{
char *from = NULL, *to = NULL;
- int len;
+ size_t from_len, to_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
- &from, &len) == FAILURE) {
+ &from, &from_len) == FAILURE) {
return;
}
- to = (char *)emalloc(len*2+1);
- len = (int)PQescapeString(to, from, strlen(from));
- if (len < 0) {
- efree(to);
- RETURN_FALSE;
- }
- RETURN_STRINGL(to, len, 0);
+ to = (char *)emalloc(from_len*2+1);
+ to_len = (int)PQescapeString(to, from, from_len);
+ RETURN_STRINGL(to, to_len, 0);
}
/* }}} */
@@ -2412,18 +2408,14 @@ PHP_FUNCTION(pg_escape_string)
PHP_FUNCTION(pg_escape_bytea)
{
char *from = NULL, *to = NULL;
- int len;
+ size_t from_len, to_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
- &from, &len) == FAILURE) {
+ &from, &from_len) == FAILURE) {
return;
}
- to = (char *)PQescapeBytea((unsigned char*)from, strlen(from), (size_t *)&len);
- if (len < 0) {
- /* Don't need to free "to" here*/
- RETURN_FALSE;
- }
- RETURN_STRINGL(to, len, 1);
+ to = (char *)PQescapeBytea((unsigned char*)from, from_len, &to_len);
+ RETVAL_STRINGL(to, to_len-1, 1); /* to_len includes addtional '\0' */
free(to);
}
/* }}} */