Commit cf5e25a9 authored by Juha Reunanen's avatar Juha Reunanen Committed by Davis E. King
Browse files

Problem: integer overflow when calculating sizes (may happen e.g. with very large images) (#1148)

* Problem: integer overflow when calculating sizes (may happen e.g. with very large images)
Solution: change some types from (unsigned) long to size_t

# Conflicts:
#	dlib/dnn/tensor.h

* Fix the fact that std::numeric_limits<unsigned long>::max() isn't always the same number

* Revert serialization changes

* Review fix: use long long instead of size_t

* From long to long long all the way

* Change more types to (hopefully) make the compiler happy

* Change many more types to size_t

* Change even more types to size_t

* Minor type changes
parent 1cf6dbf4
...@@ -100,7 +100,7 @@ namespace dlib ...@@ -100,7 +100,7 @@ namespace dlib
); );
// functions from the enumerable interface // functions from the enumerable interface
inline unsigned long size ( inline size_t size (
) const; ) const;
inline bool at_start ( inline bool at_start (
...@@ -328,7 +328,7 @@ namespace dlib ...@@ -328,7 +328,7 @@ namespace dlib
typename hash_table, typename hash_table,
typename mem_manager typename mem_manager
> >
unsigned long hash_map_kernel_1<domain,range,expnum,hash_table,mem_manager>:: size_t hash_map_kernel_1<domain,range,expnum,hash_table,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -85,7 +85,7 @@ namespace dlib ...@@ -85,7 +85,7 @@ namespace dlib
); );
// functions from the enumerable interface // functions from the enumerable interface
inline unsigned long size ( inline size_t size (
) const; ) const;
inline bool at_start ( inline bool at_start (
...@@ -266,7 +266,7 @@ namespace dlib ...@@ -266,7 +266,7 @@ namespace dlib
typename hash_table, typename hash_table,
typename mem_manager typename mem_manager
> >
unsigned long hash_set_kernel_1<T,expnum,hash_table,mem_manager>:: size_t hash_set_kernel_1<T,expnum,hash_table,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -145,7 +145,7 @@ namespace dlib ...@@ -145,7 +145,7 @@ namespace dlib
); );
// functions from the enumerable interface // functions from the enumerable interface
inline unsigned long size ( inline size_t size (
) const; ) const;
bool at_start ( bool at_start (
...@@ -336,7 +336,7 @@ namespace dlib ...@@ -336,7 +336,7 @@ namespace dlib
typename mem_manager, typename mem_manager,
typename compare typename compare
> >
unsigned long hash_table_kernel_1<domain,range,mem_manager,compare>:: size_t hash_table_kernel_1<domain,range,mem_manager,compare>::
size( size(
) const ) const
{ {
......
...@@ -116,7 +116,7 @@ namespace dlib ...@@ -116,7 +116,7 @@ namespace dlib
); );
// functions from the enumerable interface // functions from the enumerable interface
inline unsigned long size ( inline size_t size (
) const; ) const;
inline bool at_start ( inline bool at_start (
...@@ -266,7 +266,7 @@ namespace dlib ...@@ -266,7 +266,7 @@ namespace dlib
typename mem_manager, typename mem_manager,
typename compare typename compare
> >
unsigned long hash_table_kernel_2<domain,range,bst_base,mem_manager,compare>:: size_t hash_table_kernel_2<domain,range,bst_base,mem_manager,compare>::
size( size(
) const ) const
{ {
......
...@@ -55,7 +55,7 @@ namespace dlib ...@@ -55,7 +55,7 @@ namespace dlib
const image_type& img const image_type& img
); );
inline unsigned long size ( inline size_t size (
) const; ) const;
inline long nr ( inline long nr (
...@@ -280,7 +280,7 @@ namespace dlib ...@@ -280,7 +280,7 @@ namespace dlib
typename feature_extractor, typename feature_extractor,
typename hash_function_type typename hash_function_type
> >
unsigned long binned_vector_feature_image<feature_extractor,hash_function_type>:: size_t binned_vector_feature_image<feature_extractor,hash_function_type>::
size ( size (
) const ) const
{ {
......
...@@ -132,7 +132,7 @@ namespace dlib ...@@ -132,7 +132,7 @@ namespace dlib
operator() as defined below. operator() as defined below.
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -73,8 +73,8 @@ namespace dlib ...@@ -73,8 +73,8 @@ namespace dlib
inline void unload( inline void unload(
) { clear(); } ) { clear(); }
inline unsigned long size ( inline size_t size (
) const { return static_cast<unsigned long>(nr()*nc()); } ) const { return static_cast<size_t>(nr()*nc()); }
inline long nr ( inline long nr (
) const { return num_block_rows; } ) const { return num_block_rows; }
......
...@@ -132,7 +132,7 @@ namespace dlib ...@@ -132,7 +132,7 @@ namespace dlib
Both sequence 1 and sequence 2 should have the same effect on H. Both sequence 1 and sequence 2 should have the same effect on H.
!*/ !*/
inline unsigned long size ( inline size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -56,7 +56,7 @@ namespace dlib ...@@ -56,7 +56,7 @@ namespace dlib
const image_type& img const image_type& img
); );
inline unsigned long size ( inline size_t size (
) const; ) const;
inline long nr ( inline long nr (
...@@ -325,7 +325,7 @@ namespace dlib ...@@ -325,7 +325,7 @@ namespace dlib
typename feature_extractor, typename feature_extractor,
typename hash_function_type typename hash_function_type
> >
unsigned long hashed_feature_image<feature_extractor,hash_function_type>:: size_t hashed_feature_image<feature_extractor,hash_function_type>::
size ( size (
) const ) const
{ {
......
...@@ -125,7 +125,7 @@ namespace dlib ...@@ -125,7 +125,7 @@ namespace dlib
operator() as defined below. operator() as defined below.
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -89,8 +89,8 @@ namespace dlib ...@@ -89,8 +89,8 @@ namespace dlib
inline void unload( inline void unload(
) { clear(); } ) { clear(); }
inline unsigned long size ( inline size_t size (
) const { return static_cast<unsigned long>(nr()*nc()); } ) const { return static_cast<size_t>(nr()*nc()); }
inline long nr ( inline long nr (
) const { return num_block_rows; } ) const { return num_block_rows; }
......
...@@ -188,7 +188,7 @@ namespace dlib ...@@ -188,7 +188,7 @@ namespace dlib
Both sequence 1 and sequence 2 should have the same effect on H. Both sequence 1 and sequence 2 should have the same effect on H.
!*/ !*/
inline unsigned long size ( inline size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -53,7 +53,7 @@ namespace dlib ...@@ -53,7 +53,7 @@ namespace dlib
const image_type& img const image_type& img
); );
inline unsigned long size ( inline size_t size (
) const; ) const;
inline long nr ( inline long nr (
...@@ -250,7 +250,7 @@ namespace dlib ...@@ -250,7 +250,7 @@ namespace dlib
template < template <
typename feature_extractor typename feature_extractor
> >
unsigned long nearest_neighbor_feature_image<feature_extractor>:: size_t nearest_neighbor_feature_image<feature_extractor>::
size ( size (
) const ) const
{ {
......
...@@ -102,7 +102,7 @@ namespace dlib ...@@ -102,7 +102,7 @@ namespace dlib
operator() as defined below. operator() as defined below.
!*/ !*/
inline unsigned long size ( inline size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -193,7 +193,7 @@ namespace dlib ...@@ -193,7 +193,7 @@ namespace dlib
num_cols = 0; num_cols = 0;
} }
inline unsigned long size ( inline size_t size (
) const { return static_cast<unsigned long>(nr()*nc()); } ) const { return static_cast<unsigned long>(nr()*nc()); }
inline long nr ( inline long nr (
......
...@@ -197,7 +197,7 @@ namespace dlib ...@@ -197,7 +197,7 @@ namespace dlib
Both sequence 1 and sequence 2 should have the same effect on H. Both sequence 1 and sequence 2 should have the same effect on H.
!*/ !*/
inline unsigned long size ( inline size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -104,7 +104,7 @@ namespace dlib ...@@ -104,7 +104,7 @@ namespace dlib
- returns false if there are no more elements in the container - returns false if there are no more elements in the container
!*/ !*/
virtual unsigned long size ( virtual size_t size (
) const = 0; ) const = 0;
/*! /*!
ensures ensures
......
...@@ -54,7 +54,7 @@ namespace dlib ...@@ -54,7 +54,7 @@ namespace dlib
- #at_start() == true - #at_start() == true
!*/ !*/
virtual unsigned long size ( virtual size_t size (
) const = 0; ) const = 0;
/*! /*!
ensures ensures
...@@ -152,7 +152,7 @@ namespace dlib ...@@ -152,7 +152,7 @@ namespace dlib
- #at_start() == true - #at_start() == true
!*/ !*/
virtual unsigned long size ( virtual size_t size (
) const = 0; ) const = 0;
/*! /*!
ensures ensures
......
...@@ -63,7 +63,7 @@ namespace dlib ...@@ -63,7 +63,7 @@ namespace dlib
unsigned long& index unsigned long& index
); );
inline unsigned long size ( inline size_t size (
) const; ) const;
inline unsigned char operator[] ( inline unsigned char operator[] (
...@@ -208,7 +208,7 @@ namespace dlib ...@@ -208,7 +208,7 @@ namespace dlib
template < template <
typename sbuf typename sbuf
> >
unsigned long lzp_buffer_kernel_1<sbuf>:: size_t lzp_buffer_kernel_1<sbuf>::
size ( size (
) const ) const
{ {
......
...@@ -63,7 +63,7 @@ namespace dlib ...@@ -63,7 +63,7 @@ namespace dlib
unsigned long& index unsigned long& index
); );
inline unsigned long size ( inline size_t size (
) const; ) const;
inline unsigned char operator[] ( inline unsigned char operator[] (
...@@ -291,7 +291,7 @@ namespace dlib ...@@ -291,7 +291,7 @@ namespace dlib
template < template <
typename sbuf typename sbuf
> >
unsigned long lzp_buffer_kernel_2<sbuf>:: size_t lzp_buffer_kernel_2<sbuf>::
size ( size (
) const ) const
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment