Issue Bug Closed

#16042Incorrect bitwise operation in t3lib_cs at utf8_encode function...

Eloy Lafuente 04/13/06, 11:54 updated 05/03/06, 10:50

Description

In the section of the function where it is reading the input string and combining the bytes to create a single character,

for ($a=0;$a<$strLen;$a++) { // Traverse each char in string.
$chr=substr($str,$a,1);
$ord=ord($chr);
if (isset($this->twoByteSets[$charset])) { // If the charset has two bytes per char
$ord2 = ord($str{$a+1});
$ord = $ord<<8 & $ord2; // assume big endian

//etc…

The line

$ord = $ord<<8 & $ord2;

doesn’t seem right, isn’t this just going to discard whatever is value in $ord2? (It’s always going to & it against 0’s)

I think the correct operation here would be,

$ord = $ord<<8 | $ord2;

instead.

Received in moodle.org bug tracker, it isn’t critical for us because it’s only executed if neither iconv, mbstring nor recode are available, but…

(text copied from http://moodle.org/bugs/bug.php?op=show&bugid=5165)

P.S.: Congratulations for your new release! B-)
(issue imported from #M3251)

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.