Skip to content

Commit 5fa510a

Browse files
committed
Fix issue where in some cases the bits could be decoded to the neighbouring char
1 parent e236a0e commit 5fa510a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/Qrcode/Decoder/DecodedBitStreamParser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ private static function decodeNumericSegment(
208208
if ($threeDigitsBits >= 1000) {
209209
throw new FormatException("Too many three digit bits");
210210
}
211-
$result .= (self::toAlphaNumericChar($threeDigitsBits / 100));
212-
$result .= (self::toAlphaNumericChar(((int)round($threeDigitsBits / 10)) % 10));
211+
$result .= (self::toAlphaNumericChar(intdiv($threeDigitsBits, 100)));
212+
$result .= (self::toAlphaNumericChar(intdiv($threeDigitsBits, 10) % 10));
213213
$result .= (self::toAlphaNumericChar($threeDigitsBits % 10));
214214
$count -= 3;
215215
}
@@ -222,7 +222,7 @@ private static function decodeNumericSegment(
222222
if ($twoDigitsBits >= 100) {
223223
throw new FormatException("Too many bits: $twoDigitsBits expected < 100");
224224
}
225-
$result .= (self::toAlphaNumericChar($twoDigitsBits / 10));
225+
$result .= (self::toAlphaNumericChar(intdiv($twoDigitsBits, 10)));
226226
$result .= (self::toAlphaNumericChar($twoDigitsBits % 10));
227227
} elseif ($count == 1) {
228228
// One digit left over to read
@@ -263,7 +263,7 @@ private static function decodeAlphanumericSegment(
263263
throw new FormatException("Not enough bits available to read two expected characters");
264264
}
265265
$nextTwoCharsBits = $bits->readBits(11);
266-
$result .= (self::toAlphaNumericChar($nextTwoCharsBits / 45));
266+
$result .= (self::toAlphaNumericChar(intdiv($nextTwoCharsBits, 45)));
267267
$result .= (self::toAlphaNumericChar($nextTwoCharsBits % 45));
268268
$count -= 2;
269269
}

0 commit comments

Comments
 (0)