Fixed php float check error msg

This commit is contained in:
Madpwnhammer 2022-09-08 14:43:05 +03:00
parent a37da318fc
commit 99fbdd39e9
1 changed files with 20 additions and 10 deletions

View File

@ -548,13 +548,18 @@ function mtg_php_val_double($val)
return 1*$val;
}
function mtg_php_check_float($val)
{
if(is_float($val))
throw new Exception("Incompatible type, expected uint64, float given: $val");
}
function mtg_php_val_uint64($val)
{
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
if(is_float($val))
throw new Exception("Value not in range: $val");
mtg_php_check_float($val);
return $val;
}
@ -563,8 +568,7 @@ function mtg_php_val_int64($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
if(is_float($val))
throw new Exception("Value not in range: $val");
mtg_php_check_float($val);
return $val;
}
@ -573,7 +577,8 @@ function mtg_php_val_uint32($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
if(($val < 0 && $val < -2147483648) || ($val > 0 && $val > 0xFFFFFFFF) || is_float($val))
mtg_php_check_float($val);
if(($val < 0 && $val < -2147483648) || ($val > 0 && $val > 0xFFFFFFFF))
throw new Exception("Value not in range: $val");
return $val;
}
@ -583,7 +588,8 @@ function mtg_php_val_int32($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
if($val > 2147483647 || $val < -2147483648 || is_float($val))
mtg_php_check_float($val);
if($val > 2147483647 || $val < -2147483648)
throw new Exception("Value not in range: $val");
return $val;
}
@ -593,7 +599,8 @@ function mtg_php_val_uint16($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
if($val > 0xFFFF || $val < 0 || is_float($val))
mtg_php_check_float($val);
if($val > 0xFFFF || $val < 0)
throw new Exception("Value not in range: $val");
return $val;
}
@ -603,7 +610,8 @@ function mtg_php_val_int16($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
if($val > 32767 || $val < -32768 || is_float($val))
mtg_php_check_float($val);
if($val > 32767 || $val < -32768)
throw new Exception("Value not in range: $val");
return $val;
}
@ -613,7 +621,8 @@ function mtg_php_val_uint8($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
if($val > 0xFF || $val < 0 || is_float($val))
mtg_php_check_float($val);
if($val > 0xFF || $val < 0)
throw new Exception("Value not in range: $val");
return $val;
}
@ -623,7 +632,8 @@ function mtg_php_val_int8($val)
if(!is_numeric($val))
throw new Exception("Bad item, not a number(" . serialize($val) . ")");
$val = 1*$val;
if($val > 127 || $val < -128 || is_float($val))
mtg_php_check_float($val);
if($val > 127 || $val < -128)
throw new Exception("Value not in range: $val");
return $val;
}