A bug in function Mat::total() (Patch #2297)
Description
The function Mat::total() returns the number of elements in the matrix. But if the number of elements = 2^32, total() will return 0. If total() returns 0, create() function can not alloc memory.
The bug is cause by 32-bits integer overflow. Since Mat::rows and Mat::cols are all int types, rows * cols can cause overflow when they are great enough.
total() function should be: ( size_t type conversion added).
inline size_t Mat::total() const { if( dims <= 2 ) return (size_t)rows*cols; size_t p = 1; for( int i = 0; i < dims; i++ ) p *= size[i]; return p; }
History
Updated by Vadim Pisarevsky over 12 years ago
thanks! the patch was applied in our git repository, 0bd68a7
- Status changed from Open to Done
- Target version set to 2.4.3