develooper Front page | perl.perl5.porters | Postings from June 2017

Re: RFC: Add new string comparison macros in handy.h

Thread Previous | Thread Next
From:
Zefram
Date:
June 5, 2017 15:39
Subject:
Re: RFC: Add new string comparison macros in handy.h
Message ID:
20170605153946.GT6543@fysh.org
demerphq wrote:
>So the difference with the 'str' version is that str() considers a
>null byte to be end of string, and mem() does not. Is there any case
>where using memcmp() instead of str[n]cmp() is wrong for this type of
>macro?

Yes.  In mem* the length argument states absolutely the length of the
operands, but in strn* the length argument states the *maximum* length of
the operands, with a nul able to terminate them earlier.  Thus applying
a mem* function where a strn* function is really needed may result in
reading past the end of an operand, possibly into unmapped memory.

-zefram

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About