CVS update: php3/functions

From: Date: Tue, 05 Jan 1999 12:47:47 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-3277@lists.php.net to get a copy of this message
Date: Tuesday January 5, 1999 @ 7:47 Author: sas Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv19090 Modified Files: string.c Log Message: str_to_str assumed that realloc will (a) always succeed and (b) always return a valid ptr. It should work now also, if neither is the case. Index: php3/functions/string.c diff -c php3/functions/string.c:1.165 php3/functions/string.c:1.166 *** php3/functions/string.c:1.165 Mon Jan 4 12:31:19 1999 --- php3/functions/string.c Tue Jan 5 07:47:43 1999 *************** *** 30,36 **** */ ! /* $Id: string.c,v 1.165 1999/01/04 17:31:19 fmk Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif --- 30,36 ---- */ ! /* $Id: string.c,v 1.166 1999/01/05 12:47:43 sas Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif *************** *** 1341,1353 **** char *r, *s; char *end = haystack + length; char *new; new = malloc(length); /* we jump through haystack searching for the needle. hurray! */ for(p = haystack, q = new; (r = _php3_memnstr(p, needle, needle_len, end));) { /* this ain't optimal. you could call it `efficient memory usage' */ ! realloc(new, (q - new) + (r - p) + (str_len) + 1); memcpy(q, p, r - p); q += r - p; memcpy(q, str, str_len); --- 1341,1364 ---- char *r, *s; char *end = haystack + length; char *new; + char *off; new = malloc(length); /* we jump through haystack searching for the needle. hurray! */ for(p = haystack, q = new; (r = _php3_memnstr(p, needle, needle_len, end));) { /* this ain't optimal. you could call it `efficient memory usage' */ ! off = realloc(new, (q - new) + (r - p) + (str_len) + 1); ! if(off != new) { ! if(!off) { ! /* we should raise a warning here */ ! if(_new_length) *_new_length = q - new; ! return new; ! } ! /* correct pointers */ ! q += off - new; ! new = off; ! } memcpy(q, p, r - p); q += r - p; memcpy(q, str, str_len); -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#3277) next »