cvs: php4 /ext/standard string.c

From: Date: Sun, 05 Aug 2001 19:38:49 +0000
Subject: cvs: php4 /ext/standard string.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-6585@lists.php.net to get a copy of this message
jeroen Sun Aug 5 15:38:49 2001 EDT Modified files: /php4/ext/standard string.c Log: Error-handling for the second parameter of [l|r]trim Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.218 php4/ext/standard/string.c:1.219 --- php4/ext/standard/string.c:1.218 Sat Aug 4 12:53:57 2001 +++ php4/ext/standard/string.c Sun Aug 5 15:38:49 2001 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.218 2001/08/04 16:53:57 thies Exp $ */ +/* $Id: string.c,v 1.219 2001/08/05 19:38:49 jeroen Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -406,22 +406,48 @@ /* {{{ php_charmask * Fills a 256-byte bytemask with input. You can specify a range like 'a..z', * it needs to be incrementing. + * Returns: FAILURE/SUCCESS wether the input was correct (i.e. no range errors) */ -void php_charmask(unsigned char *input, int len, char *mask) +int php_charmask(unsigned char *input, int len, char *mask) { unsigned char *end; unsigned char c; + int result = SUCCESS; memset(mask, 0, 256); for (end=input+len; input<end; input++) { c=*input; - if (input+3<end && *(input+1) == '.' && *(input+2) == '.' - && *(input+3) >= c) { - memset(mask+c, 1, *(input+3) - c + 1); + if (input+3<end && input[1] == '.' && input[2] == '.' + && input[3] >= c) { + memset(mask+c, 1, input[3] - c + 1); input+=3; - } else + } else if (input+1<end && input[0] == '.' && input[1] == '.') { + /* Error, try to be as helpful as possible: + (a range ending/starting with '.' won't be captured here) */ + if (end-len>=input) { /* there was no 'left' char */ + php_error(E_WARNING,"Invalid '..'-range passed to %s(), no character to the left of '..'",get_active_function_name(TSRMLS_C)); + result = FAILURE; + continue; + } + if (input+2>=end) { /* there is no 'right' char */ + php_error(E_WARNING,"Invalid '..'-range passed to %s(), no character to the right of '..'",get_active_function_name(TSRMLS_C)); + result = FAILURE; + continue; + } + if (input[-1] > input[2]) { /* wrong order */ + php_error(E_WARNING,"Invalid '..'-range passed to %s(), '..'-range needs to be incrementing",get_active_function_name(TSRMLS_C)); + result = FAILURE; + continue; + } + /* FIXME: better error (a..b..c is the only left possibility?) */ + php_error(E_WARNING,"Invalid '..'-range passed to %s()",get_active_function_name(TSRMLS_C)); + result = FAILURE; + continue; + } else { mask[c]=1; + } } + return result; } /* }}} */

« previous php.cvs (#6585) next »