From 6d613ed8ce46f1f142a9ecbc341423655140f2ee Mon Sep 17 00:00:00 2001 From: Nathan Reed Date: Thu, 10 Sep 2015 01:13:54 -0700 Subject: [PATCH 1/2] Fix variable-shadowing warnings that appear in VS2015 on /W4 --- stb_image.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/stb_image.h b/stb_image.h index b9b265f..cf124eb 100644 --- a/stb_image.h +++ b/stb_image.h @@ -3502,7 +3502,7 @@ static int stbi__zbuild_huffman(stbi__zhuffman *z, stbi_uc *sizelist, int num) z->size [c] = (stbi_uc ) s; z->value[c] = (stbi__uint16) i; if (s <= STBI__ZFAST_BITS) { - int k = stbi__bit_reverse(next_code[s],s); + k = stbi__bit_reverse(next_code[s],s); while (k < (1 << STBI__ZFAST_BITS)) { z->fast[k] = fastv; k += (1 << s); @@ -4111,8 +4111,7 @@ static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 r } if (img_n != out_n) { // insert alpha = 255 - stbi_uc *cur = a->out + stride*j; - int i; + cur = a->out + stride*j; if (img_n == 1) { for (i=x-1; i >= 0; --i) { cur[i*2+1] = 255; @@ -4909,8 +4908,8 @@ static stbi_uc *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int if ( !tga_indexed && !tga_is_RLE) { for (i=0; i < tga_height; ++i) { - int y = tga_inverted ? tga_height -i - 1 : i; - stbi_uc *tga_row = tga_data + y*tga_width*tga_comp; + int row = tga_inverted ? tga_height -i - 1 : i; + stbi_uc *tga_row = tga_data + row*tga_width*tga_comp; stbi__getn(s, tga_row, tga_width * tga_comp); } } else { @@ -5351,7 +5350,6 @@ static stbi_uc *stbi__pic_load_core(stbi__context *s,int width,int height,int *c if (count >= 128) { // Repeated stbi_uc value[4]; - int i; if (count==128) count = stbi__get16be(s); @@ -5593,7 +5591,7 @@ static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g) bits |= (stbi__int32) stbi__get8(s) << valid_bits; valid_bits += 8; } else { - stbi__int32 code = bits & codemask; + code = bits & codemask; bits >>= codesize; valid_bits -= codesize; // @OPTIMIZE: is there some way we can accelerate the non-clear path? From 26c98260b66b36c5256f9e51aabaad49220bd5d0 Mon Sep 17 00:00:00 2001 From: Nathan Reed Date: Thu, 10 Sep 2015 01:20:35 -0700 Subject: [PATCH 2/2] Fix warnings about "conversion to a greater size" that appear in VS2015 in x64 with /W4. The warning concerns the return value of stbi_err, which is an int, being converted to a pointer. In VS2015 it seems casting directly from a 32-bit int to a 64-bit pointer triggers this warning. Worked around by first converting to a 64-bit int (here size_t) and then to a pointer. --- stb_image.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stb_image.h b/stb_image.h index cf124eb..a301fd4 100644 --- a/stb_image.h +++ b/stb_image.h @@ -902,8 +902,8 @@ static void *stbi__malloc(size_t size) #define stbi__err(x,y) stbi__err(x) #endif -#define stbi__errpf(x,y) ((float *) (stbi__err(x,y)?NULL:NULL)) -#define stbi__errpuc(x,y) ((unsigned char *) (stbi__err(x,y)?NULL:NULL)) +#define stbi__errpf(x,y) ((float *)(size_t) (stbi__err(x,y)?NULL:NULL)) +#define stbi__errpuc(x,y) ((unsigned char *)(size_t) (stbi__err(x,y)?NULL:NULL)) STBIDEF void stbi_image_free(void *retval_from_stbi_load) {