diff --git a/crnlib/stb_image_write.h b/crnlib/stb_image_write.h index e4b32ed1..63ce0438 100644 --- a/crnlib/stb_image_write.h +++ b/crnlib/stb_image_write.h @@ -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; @@ -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; } @@ -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; @@ -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) { @@ -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); } STBIW_FREE(line_buffer); zlib = stbi_zlib_compress(filt, y*( x*n+1), &zlen, stbi_write_png_compression_level);