mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
readInt/Float/LDouble/LLong will return 0 if str has not enough bytes
This commit is contained in:
parent
b4873bfd3b
commit
e16f3f5668
1 changed files with 5 additions and 2 deletions
|
|
@ -576,7 +576,7 @@ class Utils{
|
|||
}
|
||||
|
||||
public static function readInt($str){
|
||||
if(strlen($str) <= 0) return;
|
||||
if(strlen($str) < 4) return 0;
|
||||
|
||||
return @unpack("N", $str)[1] << 32 >> 32; //php has no signed long unpack
|
||||
}
|
||||
|
|
@ -589,7 +589,8 @@ class Utils{
|
|||
}
|
||||
|
||||
public static function readFloat($str){
|
||||
list(, $value) = unpack("G", $str);
|
||||
if(strlen($str) < 4) return 0;
|
||||
list(, $value) = @unpack("G", $str);
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
|
@ -611,6 +612,7 @@ class Utils{
|
|||
}
|
||||
|
||||
public static function readLDouble($str){
|
||||
if(strlen($str) < 8) return 0;
|
||||
list(, $value) = @unpack("e", $str);
|
||||
return $value;
|
||||
}
|
||||
|
|
@ -620,6 +622,7 @@ class Utils{
|
|||
}
|
||||
|
||||
public static function readLLong($str){
|
||||
if(strlen($str) < 8) return 0;
|
||||
return unpack("P", $str)[1];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue