CVS update: php3/functions

From: Date: Mon, 10 May 1999 20:50:20 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-5492@lists.php.net to get a copy of this message
Date: Monday May 10, 1999 @ 16:50 Author: sas Update of /repository/php3/functions In directory php:/tmp/cvs-serv31042/functions Modified Files: dba.c dba_db2.c string.c Log Message: - revised str_replace, incorporated fix by Michael Krause - some additional checking in DBA - DBA passes all tests now Index: php3/functions/dba.c diff -u php3/functions/dba.c:1.14 php3/functions/dba.c:1.15 --- php3/functions/dba.c:1.14 Mon May 10 07:52:05 1999 +++ php3/functions/dba.c Mon May 10 16:50:19 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dba.c,v 1.14 1999/05/10 11:52:05 sas Exp $ */ +/* $Id: dba.c,v 1.15 1999/05/10 20:50:19 sas Exp $ */ #include "php.h" @@ -126,6 +126,13 @@ dba_optimize_##x, dba_sync_##x \ }, +/* check whether the user has write access */ +#define DBA_WRITE_CHECK \ + if(info->mode != DBA_WRITER && info->mode != DBA_TRUNC) { \ + php3_error(E_WARNING, "you cannot perform a modification to a database without proper access"); \ + RETURN_FALSE; \ + } + #define GLOBAL(a) a /* }}} */ @@ -190,7 +197,7 @@ { dba_handler *hptr; - PUTS("V1 ($Id: dba.c,v 1.14 1999/05/10 11:52:05 sas Exp $)"); + PUTS("V1 ($Id: dba.c,v 1.15 1999/05/10 20:50:19 sas Exp $)"); for(hptr = handler; hptr->name; hptr++) { PUTS(" "); PUTS(hptr->name); @@ -210,6 +217,8 @@ convert_to_string(val); DBA_ID_GET; + DBA_WRITE_CHECK; + if(info->hnd->update(info, VALLEN(key), VALLEN(val), mode)) RETURN_TRUE; RETURN_FALSE; @@ -367,7 +376,7 @@ DBA_ID_GET2; if((val = info->hnd->fetch(info, VALLEN(key), &len)) != NULL) { - RETVAL_STRINGL(val, len, 0); + RETURN_STRINGL(val, len, 0); } RETURN_FALSE; } @@ -409,6 +418,8 @@ { DBA_ID_GET2; + DBA_WRITE_CHECK; + if(info->hnd->delete(info, VALLEN(key))) RETURN_TRUE; RETURN_FALSE; @@ -437,6 +448,7 @@ { DBA_ID_GET1; + DBA_WRITE_CHECK; if(info->hnd->optimize(info) == SUCCESS) { RETURN_TRUE; } Index: php3/functions/dba_db2.c diff -u php3/functions/dba_db2.c:1.6 php3/functions/dba_db2.c:1.7 --- php3/functions/dba_db2.c:1.6 Mon May 10 07:52:05 1999 +++ php3/functions/dba_db2.c Mon May 10 16:50:19 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dba_db2.c,v 1.6 1999/05/10 11:52:05 sas Exp $ */ +/* $Id: dba_db2.c,v 1.7 1999/05/10 20:50:19 sas Exp $ */ #include "php.h" @@ -182,8 +182,12 @@ memset(&gval, 0, sizeof(gval)); if(!dba->cursor->c_get(dba->cursor, &gkey, &gval, DB_NEXT)) { - nkey = estrndup(gkey.data, gkey.size); - if(newlen) *newlen = gkey.size; + if(gkey.data) { + nkey = estrndup(gkey.data, gkey.size); + if(newlen) *newlen = gkey.size; + free(gkey.data); + } + if(gval.data) free(gval.data); } return nkey; } Index: php3/functions/string.c diff -u php3/functions/string.c:1.186 php3/functions/string.c:1.187 --- php3/functions/string.c:1.186 Thu Apr 22 09:19:51 1999 +++ php3/functions/string.c Mon May 10 16:50:19 1999 @@ -30,7 +30,7 @@ */ -/* $Id: string.c,v 1.186 1999/04/22 13:19:51 ssb Exp $ */ +/* $Id: string.c,v 1.187 1999/05/10 20:50:19 sas Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif @@ -1348,7 +1348,7 @@ *target = 0; } -#if 0 +#if 1 /* * this is a binary safe equivalent to strnstr * note that we don't check for the end in str_to_str but here @@ -1360,8 +1360,8 @@ char *p = haystack; char *s = NULL; - for(; p < end - needle_len && - (s = memchr(p, *needle, end - p - needle_len)); p = s + 1) { + for(; p <= end - needle_len && + (s = memchr(p, *needle, end - p - needle_len + 1)); p = s + 1) { if(memcmp(s, needle, needle_len) == 0) return s; } @@ -1383,12 +1383,12 @@ char *new; char *off; - new = malloc(length); + new = emalloc(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); + off = erealloc(new, (q - new) + (r - p) + (str_len) + 1); if(off != new) { if(!off) { goto finish; @@ -1406,7 +1406,7 @@ /* if there is a rest, copy it */ if((end - p) > 0) { s = (q) + (end - p); - off = realloc(new, s - new + 1); + off = erealloc(new, s - new + 1); if(off != new) { if(!off) { goto finish; @@ -1423,8 +1423,9 @@ if(_new_length) *_new_length = q - new; return new; } -#endif +#else + static char *_php3_memstr(char *s, char *c, size_t n, size_t m) { char *p; @@ -1437,7 +1438,7 @@ #define ATTCHSTR(st, sz) \ nl += sz; \ - n = realloc(n, nl + 1); \ + n = erealloc(n, nl + 1); \ memcpy(n + no, st, sz); \ no += sz @@ -1471,6 +1472,7 @@ } #undef ATTCHSTR +#endif /* {{{ proto string str_replace(string needle, string str, string haystack) Replace all occurrences of needle in haystack with str */ @@ -1478,6 +1480,7 @@ { pval *haystack, *needle, *str; char *new; + int len = 0; if(ARG_COUNT(ht) != 3 || getParameters(ht, 3, &needle, &str, &haystack) == FAILURE) { @@ -1493,14 +1496,16 @@ return; } + if(needle->value.str.len == 0) { + php3_error(E_WARNING, "The length of the needle must not be 0"); + RETURN_FALSE; + } + new = _php3_str_to_str(haystack->value.str.val, haystack->value.str.len, needle->value.str.val, needle->value.str.len, str->value.str.val, str->value.str.len, - &return_value->value.str.len); - return_value->value.str.val = emalloc(return_value->value.str.len + 1); - memcpy(return_value->value.str.val, new, return_value->value.str.len + 1); - free(new); - return_value->type = IS_STRING; + &len); + RETURN_STRINGL(new, len, 0); } /* }}} */ -- 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 (#5492) next »