mysqludf/lib_mysqludf_preg — pull request #1 by dkhenry (2012-09-17 14:51:25+00:00)
Title:  preg_position gives random results if invalid group is given 

If you were to do something like:

SELECT preg_position( '/(o)/', 'The quick brown fox.', 2, 1 );

it would give you a random value instead of NULL.

The code for it shows that it sets it's count to be 3*n+1 (for n groups) in preg.c in pregCreateOffsetsVector() :

152
153 ++oveccount ; // for 0
154 oveccount *= 3 ; // 2 for offset info , 1 for pcre internals
155 ovec = malloc( sizeof( int ) * oveccount ) ;
156 if( !ovec )

and this is used in preg_position() :