Skip to content

Commit

Permalink
attempt to silence codeql
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Jun 25, 2024
1 parent 154a8b6 commit 1eb136b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions crnlib/stb_image_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ STBIWDEF int stbi_write_hdr(char const *filename, int x, int y, int comp, const
static void *stbiw__sbgrowf(void **arr, int increment, int itemsize)
{
int m = *arr ? 2*stbiw__sbm(*arr)+increment : increment+1;
void *p = STBIW_REALLOC_SIZED(*arr ? stbiw__sbraw(*arr) : 0, *arr ? (stbiw__sbm(*arr)*itemsize + sizeof(int)*2) : 0, itemsize * m + sizeof(int)*2);
void *p = STBIW_REALLOC_SIZED(*arr ? stbiw__sbraw(*arr) : 0, *arr ? (stbiw__sbm(*arr)*itemsize + sizeof(int)*2) : 0, (size_t)itemsize * (size_t)m + sizeof(int)*2);
STBIW_ASSERT(p);
if (p) {
if (!*arr) ((int *) p)[1] = 0;
Expand Down Expand Up @@ -1100,7 +1100,7 @@ static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, int
int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes;

if (type==0) {
memcpy(line_buffer, z, width*n);
memcpy(line_buffer, z, (size_t)width * (size_t)n);
return;
}

Expand Down Expand Up @@ -1132,7 +1132,8 @@ STBIWDEF unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int s
unsigned char sig[8] = { 137,80,78,71,13,10,26,10 };
unsigned char *out,*o, *filt, *zlib;
signed char *line_buffer;
int j,zlen;
int zlen;
size_t j;

if (stride_bytes == 0)
stride_bytes = x * n;
Expand All @@ -1141,8 +1142,8 @@ STBIWDEF unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int s
force_filter = -1;
}

filt = (unsigned char *) STBIW_MALLOC((x*n+1) * y); if (!filt) return 0;
line_buffer = (signed char *) STBIW_MALLOC(x * n); if (!line_buffer) { STBIW_FREE(filt); return 0; }
filt = (unsigned char *) STBIW_MALLOC(((size_t)x * (size_t)n+1) * (size_t)y); if (!filt) return 0;
line_buffer = (signed char *) STBIW_MALLOC((size_t)x * (size_t)n); if (!line_buffer) { STBIW_FREE(filt); return 0; }
for (j=0; j < y; ++j) {
int filter_type;
if (force_filter > -1) {
Expand All @@ -1169,8 +1170,8 @@ STBIWDEF unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int s
}
}
// when we get here, filter_type contains the filter type, and line_buffer contains the data
filt[j*(x*n+1)] = (unsigned char) filter_type;
STBIW_MEMMOVE(filt+j*(x*n+1)+1, line_buffer, x*n);
filt[j * ((size_t)x * (size_t)n + 1)] = (unsigned char) filter_type;
STBIW_MEMMOVE(filt + j * ((size_t)x * (size_t)n + 1) + 1, line_buffer, x*n);

Check failure

Code scanning / CodeQL

Multiplication result converted to larger type High

Multiplication result may overflow 'int' before it is converted to 'size_t'.
}
STBIW_FREE(line_buffer);
zlib = stbi_zlib_compress(filt, y*( x*n+1), &zlen, stbi_write_png_compression_level);
Expand Down

0 comments on commit 1eb136b

Please sign in to comment.