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

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
...@@ -106,7 +106,7 @@ namespace dlib ...@@ -106,7 +106,7 @@ namespace dlib
} }
explicit array ( explicit array (
unsigned long new_size size_t new_size
) : ) :
array_size(0), array_size(0),
max_array_size(0), max_array_size(0),
...@@ -125,22 +125,22 @@ namespace dlib ...@@ -125,22 +125,22 @@ namespace dlib
); );
inline const T& operator[] ( inline const T& operator[] (
unsigned long pos size_t pos
) const; ) const;
inline T& operator[] ( inline T& operator[] (
unsigned long pos size_t pos
); );
void set_size ( void set_size (
unsigned long size size_t size
); );
inline unsigned long max_size( inline size_t max_size(
) const; ) const;
void set_max_size( void set_max_size(
unsigned long max size_t max
); );
void swap ( void swap (
...@@ -148,7 +148,7 @@ namespace dlib ...@@ -148,7 +148,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 (
...@@ -173,7 +173,7 @@ namespace dlib ...@@ -173,7 +173,7 @@ namespace dlib
); );
void resize ( void resize (
unsigned long new_size size_t new_size
); );
const T& back ( const T& back (
...@@ -209,8 +209,8 @@ namespace dlib ...@@ -209,8 +209,8 @@ namespace dlib
typename mem_manager::template rebind<T>::other pool; typename mem_manager::template rebind<T>::other pool;
// data members // data members
unsigned long array_size; size_t array_size;
unsigned long max_array_size; size_t max_array_size;
T* array_elements; T* array_elements;
mutable T* pos; mutable T* pos;
...@@ -248,7 +248,7 @@ namespace dlib ...@@ -248,7 +248,7 @@ namespace dlib
serialize(item.max_size(),out); serialize(item.max_size(),out);
serialize(item.size(),out); serialize(item.size(),out);
for (unsigned long i = 0; i < item.size(); ++i) for (size_t i = 0; i < item.size(); ++i)
serialize(item[i],out); serialize(item[i],out);
} }
catch (serialization_error e) catch (serialization_error e)
...@@ -268,12 +268,12 @@ namespace dlib ...@@ -268,12 +268,12 @@ namespace dlib
{ {
try try
{ {
unsigned long max_size, size; size_t max_size, size;
deserialize(max_size,in); deserialize(max_size,in);
deserialize(size,in); deserialize(size,in);
item.set_max_size(max_size); item.set_max_size(max_size);
item.set_size(size); item.set_size(size);
for (unsigned long i = 0; i < size; ++i) for (size_t i = 0; i < size; ++i)
deserialize(item[i],in); deserialize(item[i],in);
} }
catch (serialization_error e) catch (serialization_error e)
...@@ -333,7 +333,7 @@ namespace dlib ...@@ -333,7 +333,7 @@ namespace dlib
> >
const T& array<T,mem_manager>:: const T& array<T,mem_manager>::
operator[] ( operator[] (
unsigned long pos size_t pos
) const ) const
{ {
// make sure requires clause is not broken // make sure requires clause is not broken
...@@ -356,7 +356,7 @@ namespace dlib ...@@ -356,7 +356,7 @@ namespace dlib
> >
T& array<T,mem_manager>:: T& array<T,mem_manager>::
operator[] ( operator[] (
unsigned long pos size_t pos
) )
{ {
// make sure requires clause is not broken // make sure requires clause is not broken
...@@ -379,7 +379,7 @@ namespace dlib ...@@ -379,7 +379,7 @@ namespace dlib
> >
void array<T,mem_manager>:: void array<T,mem_manager>::
set_size ( set_size (
unsigned long size size_t size
) )
{ {
// make sure requires clause is not broken // make sure requires clause is not broken
...@@ -405,7 +405,7 @@ namespace dlib ...@@ -405,7 +405,7 @@ namespace dlib
typename T, typename T,
typename mem_manager typename mem_manager
> >
unsigned long array<T,mem_manager>:: size_t array<T,mem_manager>::
size ( size (
) const ) const
{ {
...@@ -420,7 +420,7 @@ namespace dlib ...@@ -420,7 +420,7 @@ namespace dlib
> >
void array<T,mem_manager>:: void array<T,mem_manager>::
set_max_size( set_max_size(
unsigned long max size_t max
) )
{ {
reset(); reset();
...@@ -458,7 +458,7 @@ namespace dlib ...@@ -458,7 +458,7 @@ namespace dlib
typename T, typename T,
typename mem_manager typename mem_manager
> >
unsigned long array<T,mem_manager>:: size_t array<T,mem_manager>::
max_size ( max_size (
) const ) const
{ {
...@@ -476,8 +476,8 @@ namespace dlib ...@@ -476,8 +476,8 @@ namespace dlib
array<T,mem_manager>& item array<T,mem_manager>& item
) )
{ {
unsigned long array_size_temp = item.array_size; auto array_size_temp = item.array_size;
unsigned long max_array_size_temp = item.max_array_size; auto max_array_size_temp = item.max_array_size;
T* array_elements_temp = item.array_elements; T* array_elements_temp = item.array_elements;
item.array_size = array_size; item.array_size = array_size;
...@@ -646,7 +646,7 @@ namespace dlib ...@@ -646,7 +646,7 @@ namespace dlib
> >
void array<T,mem_manager>:: void array<T,mem_manager>::
resize ( resize (
unsigned long new_size size_t new_size
) )
{ {
if (this->max_size() < new_size) if (this->max_size() < new_size)
...@@ -654,7 +654,7 @@ namespace dlib ...@@ -654,7 +654,7 @@ namespace dlib
array temp; array temp;
temp.set_max_size(new_size); temp.set_max_size(new_size);
temp.set_size(new_size); temp.set_size(new_size);
for (unsigned long i = 0; i < this->size(); ++i) for (size_t i = 0; i < this->size(); ++i)
{ {
exchange((*this)[i],temp[i]); exchange((*this)[i],temp[i]);
} }
...@@ -769,7 +769,7 @@ namespace dlib ...@@ -769,7 +769,7 @@ namespace dlib
array temp; array temp;
temp.set_max_size(this->size()*2 + 1); temp.set_max_size(this->size()*2 + 1);
temp.set_size(this->size()+1); temp.set_size(this->size()+1);
for (unsigned long i = 0; i < this->size(); ++i) for (size_t i = 0; i < this->size(); ++i)
{ {
exchange((*this)[i],temp[i]); exchange((*this)[i],temp[i]);
} }
......
...@@ -66,7 +66,7 @@ namespace dlib ...@@ -66,7 +66,7 @@ namespace dlib
!*/ !*/
explicit array ( explicit array (
unsigned long new_size size_t new_size
); );
/*! /*!
ensures ensures
...@@ -116,7 +116,7 @@ namespace dlib ...@@ -116,7 +116,7 @@ namespace dlib
!*/ !*/
const T& operator[] ( const T& operator[] (
unsigned long pos size_t pos
) const; ) const;
/*! /*!
requires requires
...@@ -126,7 +126,7 @@ namespace dlib ...@@ -126,7 +126,7 @@ namespace dlib
!*/ !*/
T& operator[] ( T& operator[] (
unsigned long pos size_t pos
); );
/*! /*!
requires requires
...@@ -136,7 +136,7 @@ namespace dlib ...@@ -136,7 +136,7 @@ namespace dlib
!*/ !*/
void set_size ( void set_size (
unsigned long size size_t size
); );
/*! /*!
requires requires
...@@ -155,7 +155,7 @@ namespace dlib ...@@ -155,7 +155,7 @@ namespace dlib
if it does throw then the call to set_size() has no effect if it does throw then the call to set_size() has no effect
!*/ !*/
unsigned long max_size( size_t max_size(
) const; ) const;
/*! /*!
ensures ensures
...@@ -163,7 +163,7 @@ namespace dlib ...@@ -163,7 +163,7 @@ namespace dlib
!*/ !*/
void set_max_size( void set_max_size(
unsigned long max size_t max
); );
/*! /*!
ensures ensures
...@@ -198,7 +198,7 @@ namespace dlib ...@@ -198,7 +198,7 @@ namespace dlib
!*/ !*/
void resize ( void resize (
unsigned long new_size size_t new_size
); );
/*! /*!
ensures ensures
......
...@@ -312,8 +312,8 @@ namespace dlib ...@@ -312,8 +312,8 @@ namespace dlib
} }
} }
unsigned long size ( size_t size (
) const { return static_cast<unsigned long>(nc_ * nr_); } ) const { return static_cast<size_t>(nc_) * static_cast<size_t>(nr_); }
long width_step ( long width_step (
) const ) const
......
...@@ -356,7 +356,7 @@ namespace dlib ...@@ -356,7 +356,7 @@ namespace dlib
table.clear(); table.clear();
} }
unsigned long size () const { return table.size(); } size_t size () const { return table.size(); }
bool move_next() const { return table.move_next(); } bool move_next() const { return table.move_next(); }
void reset() const { table.reset(); } void reset() const { table.reset(); }
map_pair<assignment,double>& element() map_pair<assignment,double>& element()
......
...@@ -168,7 +168,7 @@ namespace dlib ...@@ -168,7 +168,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 (
...@@ -597,7 +597,7 @@ namespace dlib ...@@ -597,7 +597,7 @@ namespace dlib
typename mem_manager, typename mem_manager,
typename compare typename compare
> >
unsigned long binary_search_tree_kernel_1<domain,range,mem_manager,compare>:: size_t binary_search_tree_kernel_1<domain,range,mem_manager,compare>::
size ( size (
) const ) const
{ {
......
...@@ -169,7 +169,7 @@ namespace dlib ...@@ -169,7 +169,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 (
...@@ -543,7 +543,7 @@ namespace dlib ...@@ -543,7 +543,7 @@ namespace dlib
typename mem_manager, typename mem_manager,
typename compare typename compare
> >
unsigned long binary_search_tree_kernel_2<domain,range,mem_manager,compare>:: size_t binary_search_tree_kernel_2<domain,range,mem_manager,compare>::
size ( size (
) const ) const
{ {
......
...@@ -305,7 +305,7 @@ namespace dlib ...@@ -305,7 +305,7 @@ namespace dlib
bool move_next ( bool move_next (
) const { return options.move_next(); } ) const { return options.move_next(); }
unsigned long size ( size_t size (
) const { return options.size(); } ) const { return options.size(); }
private: private:
......
...@@ -34,7 +34,7 @@ namespace dlib ...@@ -34,7 +34,7 @@ namespace dlib
} }
} }
unsigned long size ( size_t size (
) const noexcept ) const noexcept
{ {
return items.size(); return items.size();
......
...@@ -44,7 +44,7 @@ namespace dlib ...@@ -44,7 +44,7 @@ namespace dlib
(i.e. this object contains new_size subsets, each containing exactly one element) (i.e. this object contains new_size subsets, each containing exactly one element)
!*/ !*/
unsigned long size ( size_t size (
) const noexcept; ) const noexcept;
/*! /*!
ensures ensures
......
...@@ -34,7 +34,7 @@ namespace dlib ...@@ -34,7 +34,7 @@ namespace dlib
number_of_sets = new_size; number_of_sets = new_size;
} }
unsigned long size ( size_t size (
) const noexcept ) const noexcept
{ {
return disjoint_subsets_.size(); return disjoint_subsets_.size();
......
...@@ -50,7 +50,7 @@ namespace dlib ...@@ -50,7 +50,7 @@ namespace dlib
- #get_size_of_set(i) == 1 - #get_size_of_set(i) == 1
!*/ !*/
unsigned long size ( size_t size (
) const noexcept; ) const noexcept;
/*! /*!
ensures ensures
......
...@@ -1639,17 +1639,17 @@ namespace dlib ...@@ -1639,17 +1639,17 @@ namespace dlib
float* g = grad.host(); float* g = grad.host();
const float x_scale = (grad.nc()-1)/(float)std::max<long>((gradient_input.nc()-1),1); const float x_scale = (grad.nc()-1)/(float)std::max<long>((gradient_input.nc()-1),1);
const float y_scale = (grad.nr()-1)/(float)std::max<long>((gradient_input.nr()-1),1); const float y_scale = (grad.nr()-1)/(float)std::max<long>((gradient_input.nr()-1),1);
for (long samp = 0; samp < gradient_input.num_samples(); ++samp) for (long long samp = 0; samp < gradient_input.num_samples(); ++samp)
{ {
for (long k = 0; k < gradient_input.k(); ++k) for (long long k = 0; k < gradient_input.k(); ++k)
{ {
for (long r = 0; r < gradient_input.nr(); ++r) for (long long r = 0; r < gradient_input.nr(); ++r)
{ {
const float y = r*y_scale; const float y = r*y_scale;
const long long top = static_cast<long long>(std::floor(y)); const long long top = static_cast<long long>(std::floor(y));
const long long bottom = std::min(top+1, grad.nr()-1); const long long bottom = std::min(top+1, grad.nr()-1);
const float tb_frac = y - top; const float tb_frac = y - top;
for (long c = 0; c < gradient_input.nc(); ++c) for (long long c = 0; c < gradient_input.nc(); ++c)
{ {
const float x = c*x_scale; const float x = c*x_scale;
const long long left = static_cast<long long>(std::floor(x)); const long long left = static_cast<long long>(std::floor(x));
......
...@@ -467,7 +467,7 @@ namespace dlib ...@@ -467,7 +467,7 @@ namespace dlib
!*/ !*/
explicit resizable_tensor( explicit resizable_tensor(
long long n_, long long g k_ = 1, long long nr_ = 1, long long nc_ = 1 long long n_, long long k_ = 1, long long nr_ = 1, long long nc_ = 1
); );
/*! /*!
requires requires
......
...@@ -125,7 +125,7 @@ namespace dlib ...@@ -125,7 +125,7 @@ namespace dlib
return false; return false;
} }
unsigned long size ( size_t size (
) const ) const
{ {
return rect.area() - inner_rect.area(); return rect.area() - inner_rect.area();
......
...@@ -99,7 +99,7 @@ namespace dlib ...@@ -99,7 +99,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
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -1399,7 +1399,7 @@ namespace dlib ...@@ -1399,7 +1399,7 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
unsigned long widget_group:: size_t widget_group::
size ( size (
) const ) const
{ {
...@@ -1578,7 +1578,7 @@ namespace dlib ...@@ -1578,7 +1578,7 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
unsigned long popup_menu:: size_t popup_menu::
size ( size (
) const ) const
{ {
......
...@@ -329,7 +329,7 @@ namespace dlib ...@@ -329,7 +329,7 @@ namespace dlib
const drawable& widget const drawable& widget
); );
unsigned long size ( size_t size (
) const; ) const;
void set_pos ( void set_pos (
...@@ -2039,7 +2039,7 @@ namespace dlib ...@@ -2039,7 +2039,7 @@ namespace dlib
unsigned long idx unsigned long idx
); );
unsigned long size ( size_t size (
) const; ) const;
void clear ( void clear (
......
...@@ -967,7 +967,7 @@ namespace dlib ...@@ -967,7 +967,7 @@ namespace dlib
widgets in this group and the upper left corner of get_rect(). widgets in this group and the upper left corner of get_rect().
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
...@@ -1561,7 +1561,7 @@ namespace dlib ...@@ -1561,7 +1561,7 @@ namespace dlib
- the menu_item in this with the index idx has been disabled - the menu_item in this with the index idx has been disabled
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -2470,7 +2470,7 @@ namespace dlib ...@@ -2470,7 +2470,7 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename S> template <typename S>
unsigned long list_box<S>:: size_t list_box<S>::
size ( size (
) const ) const
{ {
......
...@@ -1792,7 +1792,7 @@ namespace dlib ...@@ -1792,7 +1792,7 @@ namespace dlib
bool move_next ( bool move_next (
) const; ) const;
unsigned long size ( size_t size (
) const; ) const;
unsigned long get_selected ( unsigned long get_selected (
......
...@@ -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
{ {
......
...@@ -100,7 +100,7 @@ namespace dlib ...@@ -100,7 +100,7 @@ namespace dlib
until clear() is called and succeeds until clear() is called and succeeds
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -40,7 +40,7 @@ namespace dlib ...@@ -40,7 +40,7 @@ namespace dlib
typedef std::vector<neighbor>::const_iterator const_iterator; typedef std::vector<neighbor>::const_iterator const_iterator;
unsigned long size ( size_t size (
) const ) const
/*! /*!
ensures ensures
......
...@@ -91,7 +91,7 @@ namespace dlib ...@@ -91,7 +91,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 (
...@@ -311,7 +311,7 @@ namespace dlib ...@@ -311,7 +311,7 @@ namespace dlib
typename bst_base, typename bst_base,
typename mem_manager typename mem_manager
> >
unsigned long map_kernel_1<domain,range,bst_base,mem_manager>:: size_t map_kernel_1<domain,range,bst_base,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -50,7 +50,7 @@ namespace dlib ...@@ -50,7 +50,7 @@ namespace dlib
cv_image() : _data(0), _widthStep(0), _nr(0), _nc(0) {} cv_image() : _data(0), _widthStep(0), _nr(0), _nc(0) {}
unsigned long size () const { return static_cast<unsigned long>(_nr*_nc); } size_t size () const { return static_cast<size_t>(_nr*_nc); }
inline pixel_type* operator[](const long row ) inline pixel_type* operator[](const long row )
{ {
......
...@@ -127,7 +127,7 @@ namespace dlib ...@@ -127,7 +127,7 @@ namespace dlib
- returns the number of columns in this image - returns the number of columns in this image
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -66,7 +66,7 @@ namespace dlib ...@@ -66,7 +66,7 @@ namespace dlib
typedef T type; typedef T type;
explicit pipe ( explicit pipe (
unsigned long maximum_size size_t maximum_size
); );
virtual ~pipe ( virtual ~pipe (
...@@ -109,10 +109,10 @@ namespace dlib ...@@ -109,10 +109,10 @@ namespace dlib
bool is_enabled ( bool is_enabled (
) const; ) const;
unsigned long max_size ( size_t max_size (
) const; ) const;
unsigned long size ( size_t size (
) const; ) const;
bool enqueue ( bool enqueue (
...@@ -144,14 +144,14 @@ namespace dlib ...@@ -144,14 +144,14 @@ namespace dlib
private: private:
unsigned long pipe_size; size_t pipe_size;
const unsigned long pipe_max_size; const size_t pipe_max_size;
bool enabled; bool enabled;
T* const data; T* const data;
unsigned long first; size_t first;
unsigned long last; size_t last;
mutex m; mutex m;
signaler dequeue_sig; signaler dequeue_sig;
...@@ -181,7 +181,7 @@ namespace dlib ...@@ -181,7 +181,7 @@ namespace dlib
> >
pipe<T>:: pipe<T>::
pipe ( pipe (
unsigned long maximum_size size_t maximum_size
) : ) :
pipe_size(0), pipe_size(0),
pipe_max_size(maximum_size), pipe_max_size(maximum_size),
...@@ -313,7 +313,7 @@ namespace dlib ...@@ -313,7 +313,7 @@ namespace dlib
template < template <
typename T typename T
> >
unsigned long pipe<T>:: size_t pipe<T>::
max_size ( max_size (
) const ) const
{ {
...@@ -326,7 +326,7 @@ namespace dlib ...@@ -326,7 +326,7 @@ namespace dlib
template < template <
typename T typename T
> >
unsigned long pipe<T>:: size_t pipe<T>::
size ( size (
) const ) const
{ {
......
...@@ -38,7 +38,7 @@ namespace dlib ...@@ -38,7 +38,7 @@ namespace dlib
typedef T type; typedef T type;
explicit pipe ( explicit pipe (
unsigned long maximum_size size_t maximum_size
); );
/*! /*!
ensures ensures
...@@ -175,7 +175,7 @@ namespace dlib ...@@ -175,7 +175,7 @@ namespace dlib
- #is_dequeue_enabled() == true - #is_dequeue_enabled() == true
!*/ !*/
unsigned long max_size ( size_t max_size (
) const; ) const;
/*! /*!
ensures ensures
...@@ -183,7 +183,7 @@ namespace dlib ...@@ -183,7 +183,7 @@ namespace dlib
pipe can contain. pipe can contain.
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -103,7 +103,7 @@ namespace dlib ...@@ -103,7 +103,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 (
...@@ -402,7 +402,7 @@ namespace dlib ...@@ -402,7 +402,7 @@ namespace dlib
typename T, typename T,
typename mem_manager typename mem_manager
> >
unsigned long queue_kernel_1<T,mem_manager>:: size_t queue_kernel_1<T,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -112,7 +112,7 @@ namespace dlib ...@@ -112,7 +112,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 (
...@@ -155,13 +155,13 @@ namespace dlib ...@@ -155,13 +155,13 @@ namespace dlib
node* in; node* in;
node* out; node* out;
unsigned long queue_size; size_t queue_size;
unsigned long in_pos; size_t in_pos;
unsigned long out_pos; size_t out_pos;
mutable node* current_element; mutable node* current_element;
mutable unsigned long current_element_pos; mutable size_t current_element_pos;
mutable bool at_start_; mutable bool at_start_;
// restricted functions // restricted functions
...@@ -419,7 +419,7 @@ namespace dlib ...@@ -419,7 +419,7 @@ namespace dlib
unsigned long block_size, unsigned long block_size,
typename mem_manager typename mem_manager
> >
unsigned long queue_kernel_2<T,block_size,mem_manager>:: size_t queue_kernel_2<T,block_size,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -144,7 +144,7 @@ namespace dlib ...@@ -144,7 +144,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 (
...@@ -446,7 +446,7 @@ namespace dlib ...@@ -446,7 +446,7 @@ namespace dlib
typename T, typename T,
typename mem_manager typename mem_manager
> >
unsigned long sequence_kernel_1<T,mem_manager>:: size_t sequence_kernel_1<T,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -103,7 +103,7 @@ namespace dlib ...@@ -103,7 +103,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 (
...@@ -430,7 +430,7 @@ namespace dlib ...@@ -430,7 +430,7 @@ namespace dlib
typename T, typename T,
typename mem_manager typename mem_manager
> >
unsigned long sequence_kernel_2<T,mem_manager>:: size_t sequence_kernel_2<T,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -80,7 +80,7 @@ namespace dlib ...@@ -80,7 +80,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 (
...@@ -254,7 +254,7 @@ namespace dlib ...@@ -254,7 +254,7 @@ namespace dlib
typename bst_base, typename bst_base,
typename mem_manager typename mem_manager
> >
unsigned long set_kernel_1<T,bst_base,mem_manager>:: size_t set_kernel_1<T,bst_base,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -82,7 +82,7 @@ namespace dlib ...@@ -82,7 +82,7 @@ namespace dlib
catch (...) { buffer = 0; buffer_size = 0; throw; } catch (...) { buffer = 0; buffer_size = 0; throw; }
} }
unsigned long size ( size_t size (
) const { return buffer_size; } ) const { return buffer_size; }
void rotate_left ( void rotate_left (
......
...@@ -97,7 +97,7 @@ namespace dlib ...@@ -97,7 +97,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 (
...@@ -365,7 +365,7 @@ namespace dlib ...@@ -365,7 +365,7 @@ namespace dlib
typename T, typename T,
typename mem_manager typename mem_manager
> >
unsigned long stack_kernel_1<T,mem_manager>:: size_t stack_kernel_1<T,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -157,7 +157,7 @@ namespace dlib ...@@ -157,7 +157,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 (
...@@ -433,7 +433,7 @@ namespace dlib ...@@ -433,7 +433,7 @@ namespace dlib
typename range, typename range,
typename compare typename compare
> >
unsigned long static_map_kernel_1<domain,range,compare>:: size_t static_map_kernel_1<domain,range,compare>::
size ( size (
) const ) const
{ {
......
...@@ -52,11 +52,11 @@ namespace dlib ...@@ -52,11 +52,11 @@ namespace dlib
try try
{ {
item.clear(); item.clear();
unsigned long size; size_t size;
deserialize(size,in); deserialize(size,in);
item.set_size = size; item.set_size = size;
item.d = new T[size]; item.d = new T[size];
for (unsigned long i = 0; i < size; ++i) for (size_t i = 0; i < size; ++i)
{ {
deserialize(item.d[i],in); deserialize(item.d[i],in);
} }
...@@ -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 (
...@@ -142,7 +142,7 @@ namespace dlib ...@@ -142,7 +142,7 @@ namespace dlib
// data members // data members
unsigned long set_size; size_t set_size;
T* d; T* d;
mutable T* cur; mutable T* cur;
mutable bool at_start_; mutable bool at_start_;
...@@ -231,7 +231,7 @@ namespace dlib ...@@ -231,7 +231,7 @@ namespace dlib
set_size = source.size(); set_size = source.size();
for (unsigned long i = 0; source.size() > 0; ++i) for (size_t i = 0; source.size() > 0; ++i)
source.remove_any(d[i]); source.remove_any(d[i]);
compare comp; compare comp;
...@@ -261,7 +261,7 @@ namespace dlib ...@@ -261,7 +261,7 @@ namespace dlib
set_size = source.size(); set_size = source.size();
for (unsigned long i = 0; source.size() > 0; ++i) for (size_t i = 0; source.size() > 0; ++i)
source.remove_any(d[i]); source.remove_any(d[i]);
} }
else else
...@@ -282,10 +282,10 @@ namespace dlib ...@@ -282,10 +282,10 @@ namespace dlib
const T& item const T& item
) const ) const
{ {
unsigned long high = set_size; size_t high = set_size;
unsigned long low = 0; size_t low = 0;
unsigned long p = set_size; size_t p = set_size;
unsigned long idx; size_t idx;
while (p > 0) while (p > 0)
{ {
p = (high-low)>>1; p = (high-low)>>1;
...@@ -306,7 +306,7 @@ namespace dlib ...@@ -306,7 +306,7 @@ namespace dlib
typename T, typename T,
typename compare typename compare
> >
unsigned long static_set_kernel_1<T,compare>:: size_t static_set_kernel_1<T,compare>::
size ( size (
) const ) const
{ {
...@@ -421,7 +421,7 @@ namespace dlib ...@@ -421,7 +421,7 @@ namespace dlib
else if (cur != 0) else if (cur != 0)
{ {
++cur; ++cur;
if (static_cast<unsigned long>(cur - d) < set_size) if (static_cast<size_t>(cur - d) < set_size)
{ {
return true; return true;
} }
......
...@@ -67,7 +67,7 @@ namespace dlib ...@@ -67,7 +67,7 @@ namespace dlib
const std::vector<T>& to_std_vector( const std::vector<T>& to_std_vector(
) const { return items; } ) const { return items; }
unsigned long size ( size_t size (
) const ) const
{ {
return items.size(); return items.size();
......
...@@ -101,7 +101,7 @@ namespace dlib ...@@ -101,7 +101,7 @@ namespace dlib
- #size() == 0 - #size() == 0
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -65,7 +65,7 @@ namespace dlib ...@@ -65,7 +65,7 @@ namespace dlib
} }
template <typename kernel_type> template <typename kernel_type>
inline unsigned long size ( inline size_t size (
const typename kernel_type::sample_type& const typename kernel_type::sample_type&
) )
{ {
......
...@@ -296,7 +296,7 @@ namespace dlib ...@@ -296,7 +296,7 @@ namespace dlib
temp.swap(item.temp); temp.swap(item.temp);
} }
unsigned long size ( size_t size (
) const { return dictionary.size(); } ) const { return dictionary.size(); }
const matrix<sample_type,0,1,mem_manager_type> get_dictionary ( const matrix<sample_type,0,1,mem_manager_type> get_dictionary (
......
...@@ -173,7 +173,7 @@ namespace dlib ...@@ -173,7 +173,7 @@ namespace dlib
- swaps *this with item - swaps *this with item
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -151,7 +151,7 @@ namespace ...@@ -151,7 +151,7 @@ namespace
} }
} }
inline unsigned long size () const { return feat_image.size(); } inline size_t size () const { return feat_image.size(); }
inline long nr () const { return feat_image.nr(); } inline long nr () const { return feat_image.nr(); }
inline long nc () const { return feat_image.nc(); } inline long nc () const { return feat_image.nc(); }
......
...@@ -127,7 +127,7 @@ namespace dlib ...@@ -127,7 +127,7 @@ namespace dlib
bool move_next ( bool move_next (
) const { return list.move_next(); } ) const { return list.move_next(); }
unsigned long size ( size_t size (
) const { return list.size(); } ) const { return list.size(); }
}; };
......
...@@ -134,7 +134,7 @@ public: ...@@ -134,7 +134,7 @@ public:
} }
} }
inline unsigned long size () const { return feat_image.size(); } inline size_t size () const { return feat_image.size(); }
inline long nr () const { return feat_image.nr(); } inline long nr () const { return feat_image.nr(); }
inline long nc () const { return feat_image.nc(); } inline long nc () const { return feat_image.nc(); }
......
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