cvs: /php4/ext/standard string.c

From: Date: Mon, 06 Dec 1999 17:38:30 +0000
Subject: cvs: /php4/ext/standard string.c
Groups: php.version4 
Request: Send a blank email to php-version4+get-7539@lists.php.net to get a copy of this message
thies Mon Dec 6 12:38:30 1999 EDT Modified files: /php4/ext/standard string.c Log: @- strpos() is now binary-safe. (Thies) Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.63 php4/ext/standard/string.c:1.64 --- php4/ext/standard/string.c:1.63 Sun Dec 5 09:16:36 1999 +++ php4/ext/standard/string.c Mon Dec 6 12:37:59 1999 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.63 1999/12/05 14:16:36 rasmus Exp $ */ +/* $Id: string.c,v 1.64 1999/12/06 17:37:59 thies Exp $ */ /* Synced with php3 revision 1.193 1999-06-16 [ssb] */ @@ -34,6 +34,7 @@ #include "php_globals.h" int php_tag_find(char *tag, int len, char *set); +static inline char *php_memnstr(char *haystack, char *needle, int needle_len, char *end); /* this is read-only, so it's ok */ static char hexconvtab[] = "0123456789abcdef"; @@ -602,6 +603,8 @@ pval **haystack, **needle, **OFFSET; int offset = 0; char *found = NULL; + char *endp; + char *startp; switch(ARG_COUNT(ht)) { case 2: @@ -615,25 +618,41 @@ } convert_to_long_ex(OFFSET); offset = (*OFFSET)->value.lval; + if (offset < 0) { + php_error(E_WARNING,"offset not contained in string"); + RETURN_FALSE; + } break; default: WRONG_PARAM_COUNT; } + convert_to_string_ex(haystack); + if (offset > (*haystack)->value.str.len) { php_error(E_WARNING,"offset not contained in string"); RETURN_FALSE; } + startp = (*haystack)->value.str.val; + startp+= offset; + + endp = (*haystack)->value.str.val; + endp+= (*haystack)->value.str.len; + if ((*needle)->type == IS_STRING) { if ((*needle)->value.str.len==0) { php_error(E_WARNING,"Empty delimiter"); RETURN_FALSE; } - found = strstr((*haystack)->value.str.val+offset, (*needle)->value.str.val); + found = php_memnstr(startp, (*needle)->value.str.val, (*needle)->value.str.len, endp); } else { + char buf; + convert_to_long_ex(needle); - found = strchr((*haystack)->value.str.val+offset, (char) (*needle)->value.lval); + buf = (char) (*needle)->value.lval; + + found = php_memnstr(startp, &buf, 1, endp); } if (found) {

« previous php.version4 (#7539) next »