浏览代码

Use stbi__mad4sizes_valid() only if STBI_NO_LINEAR or STBI_NO_HDR are defined

darealshinji 8 年之前
父节点
当前提交
b6b43df186
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      stb_image.h

+ 5 - 1
stb_image.h

@@ -503,7 +503,7 @@ STBIDEF int   stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const ch
 #include <string.h>
 #include <string.h>
 #include <limits.h>
 #include <limits.h>
 
 
-#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)
+#if !defined(STBI_NO_LINEAR) && !defined(STBI_NO_HDR)
 #include <math.h>  // ldexp
 #include <math.h>  // ldexp
 #endif
 #endif
 
 
@@ -893,11 +893,13 @@ static int stbi__mad3sizes_valid(int a, int b, int c, int add)
 }
 }
 
 
 // returns 1 if "a*b*c*d + add" has no negative terms/factors and doesn't overflow
 // returns 1 if "a*b*c*d + add" has no negative terms/factors and doesn't overflow
+#if !defined(STBI_NO_LINEAR) && !defined(STBI_NO_HDR)
 static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add)
 static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add)
 {
 {
    return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) &&
    return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) &&
       stbi__mul2sizes_valid(a*b*c, d) && stbi__addsizes_valid(a*b*c*d, add);
       stbi__mul2sizes_valid(a*b*c, d) && stbi__addsizes_valid(a*b*c*d, add);
 }
 }
+#endif
 
 
 // mallocs with size overflow checking
 // mallocs with size overflow checking
 static void *stbi__malloc_mad2(int a, int b, int add)
 static void *stbi__malloc_mad2(int a, int b, int add)
@@ -912,11 +914,13 @@ static void *stbi__malloc_mad3(int a, int b, int c, int add)
    return stbi__malloc(a*b*c + add);
    return stbi__malloc(a*b*c + add);
 }
 }
 
 
+#if !defined(STBI_NO_LINEAR) && !defined(STBI_NO_HDR)
 static void *stbi__malloc_mad4(int a, int b, int c, int d, int add)
 static void *stbi__malloc_mad4(int a, int b, int c, int d, int add)
 {
 {
    if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL;
    if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL;
    return stbi__malloc(a*b*c*d + add);
    return stbi__malloc(a*b*c*d + add);
 }
 }
+#endif
 
 
 // stbi__err - error
 // stbi__err - error
 // stbi__errpf - error returning pointer to float
 // stbi__errpf - error returning pointer to float