DmitryJ added the comment:

>From the author's page at

"Note that the above Python code may access s[n], which would result in an 
IndexError exception. For the CPython implementation, this is not really a 
problem, since CPython adds trailing NULL entries to both 8-bit and Unicode 

Apparently, this flaw was known to the author, but was not documented in C code.

A possible quick-and-dirty solution is to treat m=n as a special case and 
resort to memcmp() or somesuch as there is no actual need to perform multiple 
match tries. This should fix things for bytearray and str in case str's 
implementation changes from appending a trailing NUL.


Python tracker <>
Python-bugs-list mailing list

Reply via email to