cvs: /php4/ext/pcre php_pcre.c
| From: | Andrei Zmievski | Date: | Mon, 20 Dec 1999 20:50:27 +0000 |
| Subject: | cvs: /php4/ext/pcre php_pcre.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-8253@lists.php.net to get a copy of this message | ||
andrei Mon Dec 20 15:50:27 1999 EDT
Modified files:
/php4/ext/pcre php_pcre.c
Log:
(PHP preg_quote) Made binary-safe.
@ Made preg_quote() binary-safe. (Andrei)
Index: php4/ext/pcre/php_pcre.c
diff -u php4/ext/pcre/php_pcre.c:1.33 php4/ext/pcre/php_pcre.c:1.34
--- php4/ext/pcre/php_pcre.c:1.33 Sat Dec 18 17:35:20 1999
+++ php4/ext/pcre/php_pcre.c Mon Dec 20 15:49:56 1999
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_pcre.c,v 1.33 1999/12/18 22:35:20 zeev Exp $ */
+/* $Id: php_pcre.c,v 1.34 1999/12/20 20:49:56 andrei Exp $ */
/*
TODO:
@@ -1035,6 +1035,7 @@
{
zval **in_str_arg; /* Input string argument */
char *in_str, /* Input string */
+ *in_str_end, /* End of the input string */
*out_str, /* Output string with quoted characters */
*p, /* Iterator for input string */
*q, /* Iterator for output string */
@@ -1048,10 +1049,11 @@
/* Make sure we're working with strings */
convert_to_string_ex(in_str_arg);
in_str = (*in_str_arg)->value.str.val;
+ in_str_end = (*in_str_arg)->value.str.val + (*in_str_arg)->value.str.len;
/* Nothing to do if we got an empty string */
- if (!*in_str) {
- RETVAL_STRING(empty_string, 0);
+ if (in_str == in_str_end) {
+ RETVAL_STRINGL(empty_string, 0, 0);
}
/* Allocate enough memory so that even if each character
@@ -1059,7 +1061,8 @@
out_str = emalloc(2 * (*in_str_arg)->value.str.len + 1);
/* Go through the string and quote necessary characters */
- for(p = in_str, q = out_str; (c = *p); p++) {
+ for(p = in_str, q = out_str; p != in_str_end; p++) {
+ c = *p;
switch(c) {
case '.':
case '\\':
@@ -1089,7 +1092,7 @@
*q = '\0';
/* Reallocate string and return it */
- RETVAL_STRING(erealloc(out_str, q - out_str + 1), 0);
+ RETVAL_STRINGL(erealloc(out_str, q - out_str + 1), q - out_str, 0);
}
/* }}} */