Security: Invalid read in trim comparison functions.
This is a back port of the changes from the 0.7. development branch commit
4d19713c7c113481124958284f7390b8bdc48e97.
The unit tests might also be back ported at a later time.
Writing unit tests exposed this problem.
The last1 and last2 positions could be the exclusive stop points.
The comparison checks fail to handle this situation and expect the last1 and last2 variables to not be positioned at an exclusive stop point.
This results in an invalid read.