Skip to content

Commit bb96b93

Browse files
committed
attempt to silence codeql
1 parent 154a8b6 commit bb96b93

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

crnlib/stb_image_write.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ STBIWDEF int stbi_write_hdr(char const *filename, int x, int y, int comp, const
826826
static void *stbiw__sbgrowf(void **arr, int increment, int itemsize)
827827
{
828828
int m = *arr ? 2*stbiw__sbm(*arr)+increment : increment+1;
829-
void *p = STBIW_REALLOC_SIZED(*arr ? stbiw__sbraw(*arr) : 0, *arr ? (stbiw__sbm(*arr)*itemsize + sizeof(int)*2) : 0, itemsize * m + sizeof(int)*2);
829+
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);
830830
STBIW_ASSERT(p);
831831
if (p) {
832832
if (!*arr) ((int *) p)[1] = 0;
@@ -1100,7 +1100,7 @@ static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, int
11001100
int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes;
11011101

11021102
if (type==0) {
1103-
memcpy(line_buffer, z, width*n);
1103+
memcpy(line_buffer, z, (size_t)width * (size_t)n);
11041104
return;
11051105
}
11061106

@@ -1141,8 +1141,8 @@ STBIWDEF unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int s
11411141
force_filter = -1;
11421142
}
11431143

1144-
filt = (unsigned char *) STBIW_MALLOC((x*n+1) * y); if (!filt) return 0;
1145-
line_buffer = (signed char *) STBIW_MALLOC(x * n); if (!line_buffer) { STBIW_FREE(filt); return 0; }
1144+
filt = (unsigned char *) STBIW_MALLOC(((size_t)x * (size_t)n+1) * (size_t)y); if (!filt) return 0;
1145+
line_buffer = (signed char *) STBIW_MALLOC((size_t)x * (size_t)n); if (!line_buffer) { STBIW_FREE(filt); return 0; }
11461146
for (j=0; j < y; ++j) {
11471147
int filter_type;
11481148
if (force_filter > -1) {
@@ -1169,8 +1169,8 @@ STBIWDEF unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int s
11691169
}
11701170
}
11711171
// when we get here, filter_type contains the filter type, and line_buffer contains the data
1172-
filt[j*(x*n+1)] = (unsigned char) filter_type;
1173-
STBIW_MEMMOVE(filt+j*(x*n+1)+1, line_buffer, x*n);
1172+
filt[(size_t)j * ((size_t)x * (size_t)n + 1)] = (unsigned char) filter_type;
1173+
STBIW_MEMMOVE(filt + (size_t)j * ((size_t)x * (size_t)n + 1) + 1, line_buffer, (size_t)x * (size_t)n);
11741174
}
11751175
STBIW_FREE(line_buffer);
11761176
zlib = stbi_zlib_compress(filt, y*( x*n+1), &zlen, stbi_write_png_compression_level);

0 commit comments

Comments
 (0)