mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Fixed data overflow issue when int64 value is interpreted as float/double.
This commit is contained in:
@@ -2410,7 +2410,7 @@ FileNode::operator float() const
|
||||
|
||||
if( type == INT )
|
||||
{
|
||||
return (float)readInt(p);
|
||||
return (float)readLong(p);
|
||||
}
|
||||
else if( type == REAL )
|
||||
{
|
||||
@@ -2431,7 +2431,7 @@ FileNode::operator double() const
|
||||
|
||||
if( type == INT )
|
||||
{
|
||||
return (double)readInt(p);
|
||||
return (double)readLong(p);
|
||||
}
|
||||
else if( type == REAL )
|
||||
{
|
||||
@@ -2442,6 +2442,7 @@ FileNode::operator double() const
|
||||
}
|
||||
|
||||
double FileNode::real() const { return double(*this); }
|
||||
|
||||
std::string FileNode::string() const
|
||||
{
|
||||
const uchar* p = ptr();
|
||||
|
||||
@@ -2155,6 +2155,7 @@ TEST(Core_InputOutput, FileStorage_int64_26829)
|
||||
"IntMax: 2147483647\n"
|
||||
"String4: string4\n"
|
||||
"Int64Max: 9223372036854775807\n"
|
||||
"Int64Reg: 2147484671\n"
|
||||
"String5: string5\n";
|
||||
|
||||
FileStorage fs(content, FileStorage::READ | FileStorage::MEMORY);
|
||||
@@ -2197,6 +2198,14 @@ TEST(Core_InputOutput, FileStorage_int64_26829)
|
||||
|
||||
fs["Int64Max"] >> value;
|
||||
EXPECT_EQ(value, INT64_MAX);
|
||||
|
||||
fs["Int64Reg"] >> value;
|
||||
EXPECT_EQ(value, 2147484671); // C++ INT_MAX +1024
|
||||
}
|
||||
|
||||
{
|
||||
double value = fs["Int64Reg"].real();
|
||||
EXPECT_EQ(value, 2147484671); // C++ INT_MAX +1024
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user