Skip to content

Commit

Permalink
Use size_t to avoid possible numeric overflow for the very largest im…
Browse files Browse the repository at this point in the history
…ages.
  • Loading branch information
davisking committed Apr 10, 2024
1 parent 792b744 commit 73c990d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dlib/image_loader/jpeg_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ namespace dlib
data.resize(height_*width_*output_components_);

// setup pointers to each row
for (unsigned long i = 0; i < rows.size(); ++i)
for (size_t i = 0; i < rows.size(); ++i)
rows[i] = &data[i*width_*output_components_];

// read the data into the buffer
Expand Down
12 changes: 6 additions & 6 deletions dlib/image_loader/jpeg_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ namespace dlib
#endif
image_view<T> t(t_);
t.set_size( height_, width_ );
for ( unsigned n = 0; n < height_;n++ )
for (size_t n = 0; n < height_;n++ )
{
const unsigned char* v = get_row( n );
for ( unsigned m = 0; m < width_;m++ )
for (size_t m = 0; m < width_;m++ )
{
if ( is_gray() )
{
Expand Down Expand Up @@ -74,16 +74,16 @@ namespace dlib
}

private:
const unsigned char* get_row( unsigned long i ) const
const unsigned char* get_row(size_t i) const
{
return &data[i*width_*output_components_];
}

FILE * check_file(const char* filename );
void read_image( FILE *file, const unsigned char* imgbuffer, size_t imgbuffersize );
unsigned long height_;
unsigned long width_;
unsigned long output_components_;
size_t long height_;
size_t long width_;
size_t long output_components_;
std::vector<unsigned char> data;
};

Expand Down

0 comments on commit 73c990d

Please sign in to comment.