[issue41170] Use strnlen instead of strlen when the size i known.

STINNER Victor report at bugs.python.org
Mon Sep 28 18:08:46 EDT 2020


STINNER Victor <vstinner at python.org> added the comment:

"Use strnlen instead of strlen when the size i known" rationale was "This PR changes strlen to strnlen so no buffer overruns are made when there's no null terminator", but strlen() was not called whne the string was not null terminated.

Serhiy wrote that strnlen() can be faster and that can be slower... If the goal is an optimization, a benchmark should prove it (on at least one platform).
https://github.com/python/cpython/pull/21236#issuecomment-699609949

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41170>
_______________________________________


More information about the Python-bugs-list mailing list