Skip to content

Commit 73c990d

Browse files
committed
Use size_t to avoid possible numeric overflow for the very largest images.
1 parent 792b744 commit 73c990d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

dlib/image_loader/jpeg_loader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ namespace dlib
182182
data.resize(height_*width_*output_components_);
183183

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

188188
// read the data into the buffer

dlib/image_loader/jpeg_loader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ namespace dlib
4343
#endif
4444
image_view<T> t(t_);
4545
t.set_size( height_, width_ );
46-
for ( unsigned n = 0; n < height_;n++ )
46+
for (size_t n = 0; n < height_;n++ )
4747
{
4848
const unsigned char* v = get_row( n );
49-
for ( unsigned m = 0; m < width_;m++ )
49+
for (size_t m = 0; m < width_;m++ )
5050
{
5151
if ( is_gray() )
5252
{
@@ -74,16 +74,16 @@ namespace dlib
7474
}
7575

7676
private:
77-
const unsigned char* get_row( unsigned long i ) const
77+
const unsigned char* get_row(size_t i) const
7878
{
7979
return &data[i*width_*output_components_];
8080
}
8181

8282
FILE * check_file(const char* filename );
8383
void read_image( FILE *file, const unsigned char* imgbuffer, size_t imgbuffersize );
84-
unsigned long height_;
85-
unsigned long width_;
86-
unsigned long output_components_;
84+
size_t long height_;
85+
size_t long width_;
86+
size_t long output_components_;
8787
std::vector<unsigned char> data;
8888
};
8989

0 commit comments

Comments
 (0)