-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Labels
BugFor errors / faults / flaws / inconsistencies etc.For errors / faults / flaws / inconsistencies etc.
Description
Las time when we were testing Piwik with the newest version of PHP. Actually, everything looks promising except small error which arose during archivization process.
This problem is about bit-shifting in this class: https://github.com/piwik/component-network/blob/0.2.0/src/IPUtils.php.
Look at line https://github.com/piwik/component-network/blob/0.2.0/src/IPUtils.php#L182
Sometimes variable $n
is a negative number and in the PHP7 it will throw an exception because this version of PHP introduced exceptions instead of fatal errors, null values etc.
small example:
// php 5.6
var_dump(1 << 1); // int(2)
var_dump(1 << -1); // int(-9223372036854775808)
var_dump(-1 << 1); // int(-2)
var_dump(~((1 << $n) - 1)); // int(9223372036854775807) when $n = -1
// php 7
var_dump(1 << 1); // int(2)
var_dump(1 << -1); // Uncaught ArithmeticError: Bit shift by negative number
var_dump(-1 << 1); // int(-2)
var_dump(~((1 << $n) - 1)); // Uncaught ArithmeticError: Bit shift by negative number when $n = -1
Metadata
Metadata
Assignees
Labels
BugFor errors / faults / flaws / inconsistencies etc.For errors / faults / flaws / inconsistencies etc.