Hi,<br><br>I tried to study the source code for a personal project to add SYLT support. And<br>it seems to me that the find() routine in tbytevector has a problem to handle<br>cases when byteAlign>1, which is typically the case when unicode is used.
<br><br>To be more precise, the code segment in tbytevector.cpp::template<> vectorfind()<br>is (may be) problematic. When offset > 0, it tries to "start at the next byte<br>aligned block" and call find() recursively, however, the actual code seems
<br>always to jump to one byte earlier. [toolkit/tbytevector.cpp:99]<br><br> // start at the next byte aligned block<br><br> Vector section = v.mid(offset + byteAlign - 1 - offset % byteAlign);<br> int match =
section.find(pattern, 0, byteAlign);<br> return match >= 0 ? int(match + offset) : -1;<br><br>For example, when byteAlign==2 and offset is an even number, the offset is<br>always incremented by one, and the search within "section" actually scans the
<br>pattern on odd offsets only. What is worse, when a match is found (which is<br>incorrect anyway), match + offset actually points to the place one byte earlier<br>than the match.<br><br>A quick fix can solve the problem. Note that it is obvious that when
<br>byteAlign==1, nothing will change since no real "shifting" occurs anyway.<br>Besides that, I have not tested whether it may break code anywhere else.<br><br> // start at the next byte aligned block<br>
<br>- Vector section = v.mid(offset + byteAlign - 1 - offset % byteAlign);<br>+ Vector section = v.mid(offset % byteAlign == 0 ? offset :<br>+ (offset += byteAlign - offset % byteAlign));<br> int match =
section.find(pattern, 0, byteAlign);<br>
return match >= 0 ? int(match + offset) : -1;<br><br>-Willis<br>