Arachnid / solidity-stringutils

Basic string utilities for Solidity
Apache License 2.0
1.13k stars 372 forks source link

Error in compare #32

Open aleph-v opened 6 years ago

aleph-v commented 6 years ago

This line should be "if(shortest - idx < 32){" otherwise we don't mask out the bits of the shortest string which aren't part of the string. Eg if we have two slices one with 33 bytes and one with 34 bytes the algorithm will compare the first 32 bytes then move on to the next 32 bytes, but shortest variable will be 33 so the current code will not mask out the last 31 bytes of this next chunk of memory. https://github.com/Arachnid/solidity-stringutils/blob/3c63f18245645ba600cae2191deba7221512f753/src/strings.sol#L215