commit d6a0953b7c73d3327adf1cf5d73e54d6a2044905 parent 45bf5ffe31f47541fe5a5d611505ccc8dc07cb43 Author: Michael Savage <mikejsavage@gmail.com> Date: Sun Aug 27 10:59:01 +0100 Patterns fixes Diffstat:
patterns.cc | | | 10 | +++++++--- |
diff --git a/patterns.cc b/patterns.cc @@ -533,10 +533,12 @@ bool match( Matches * matches, array< const char > str, const char * pattern ) { matches->matches = matches->matches_data.slice( 0, ms.level ); for( int i = 0; i < ms.level; i++ ) { - matches->matches_data[ i ] = array< const char >( ms.capture[ i ].init, ms.capture[ i ].len ); + ssize_t len = ms.capture[ i ].len; + if( len == CAP_POSITION ) len = 0; + matches->matches_data[ i ] = array< const char >( ms.capture[ i ].init, checked_cast< size_t >( len ) ); } - return true; + return ms.level > 0; } bool match( Matches * matches, const char * str, const char * pattern ) { @@ -575,7 +577,9 @@ void gmatch::Iterator::next() { matches.matches = matches.matches_data.slice( 0, gm->ms.level ); for( int i = 0; i < gm->ms.level; i++ ) { - matches.matches_data[ i ] = array< const char >( gm->ms.capture[ i ].init, gm->ms.capture[ i ].len ); + ssize_t len = gm->ms.capture[ i ].len; + if( len == CAP_POSITION ) len = 0; + matches.matches_data[ i ] = array< const char >( gm->ms.capture[ i ].init, checked_cast< size_t >( len ) ); } }