Package: exactimage / 0.9.1-16

Avoid-infinite-loops-generated-by-GCC-4.8-caused-by-.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
From: Sven Eckelmann <sven@narfation.org>
Date: Tue, 18 Jun 2013 00:19:01 +0200
Subject: Avoid infinite loops generated by GCC 4.8 caused by undefined
 behaviour

GCC 4.8 uses an aggressive loop optimizer which can cause unexpected runtime
behavior when the code tries to access memory in an incorrect way.

Forwarded: yes
---
 codecs/dcraw.h | 46 +++++++++++++++++++++++++++++++---------------
 1 file changed, 31 insertions(+), 15 deletions(-)

diff --git a/codecs/dcraw.h b/codecs/dcraw.h
index 3e8dd10..b115191 100644
--- a/codecs/dcraw.h
+++ b/codecs/dcraw.h
@@ -1956,6 +1956,8 @@ void CLASS quicktake_100_load_raw()
 #define PREDICTOR (c ? (buf[c][y-1][x] + buf[c][y][x+1]) / 2 \
 : (buf[c][y-1][x+1] + 2*buf[c][y-1][x] + buf[c][y][x+1]) / 4)
 
+#define ARRAY_SIZE(_array) (sizeof(_array) / sizeof((_array)[0]))
+
 void CLASS kodak_radc_load_raw()
 {
   static const char src[] = {
@@ -1994,8 +1996,12 @@ void CLASS kodak_radc_load_raw()
   s = kodak_cbpp == 243 ? 2 : 3;
   FORC(256) huff[18][c] = (8-s) << 8 | c >> s << s | 1 << (s-1);
   getbits(-1);
-  for (i=0; i < sizeof(buf)/sizeof(short); i++)
-    buf[0][0][i] = 2048;
+  for (c=0; c < ARRAY_SIZE(buf); c++) {
+    for (y=0; y < ARRAY_SIZE(buf[0]); y++) {
+      for (x=0; y < ARRAY_SIZE(buf[0][0]); x++)
+        buf[c][y][x] = 2048;
+    }
+  }
   for (row=0; row < height; row+=4) {
     FORC3 mul[c] = getbits(6);
     FORC3 {
@@ -3100,9 +3106,11 @@ void CLASS foveon_interpolate()
 
   black = (float (*)[3]) calloc (height, sizeof *black);
   for (row=0; row < height; row++) {
-    for (i=0; i < 6; i++)
-      ddft[0][0][i] = ddft[1][0][i] +
-	row / (height-1.0) * (ddft[2][0][i] - ddft[1][0][i]);
+    for (c=0; c < ARRAY_SIZE(ddft[0]); c++) {
+      for (i=0; i < ARRAY_SIZE(ddft[0][0]); i++)
+        ddft[0][c][i] = ddft[1][c][i] +
+          row / (height-1.0) * (ddft[2][c][i] - ddft[1][c][i]);
+    }
     FORC3 black[row][c] =
 	( foveon_avg (image[row*width]+c, dscr[0], cfilt) +
 	  foveon_avg (image[row*width]+c, dscr[1], cfilt) * 3
@@ -3146,9 +3154,11 @@ void CLASS foveon_interpolate()
     FORC3 black[row][c] += fsum[c]/2 + total[c]/(total[3]*100.0);
 
   for (row=0; row < height; row++) {
-    for (i=0; i < 6; i++)
-      ddft[0][0][i] = ddft[1][0][i] +
-	row / (height-1.0) * (ddft[2][0][i] - ddft[1][0][i]);
+    for (c=0; c < ARRAY_SIZE(ddft[0]); c++) {
+      for (i=0; i < ARRAY_SIZE(ddft[0][0]); i++)
+        ddft[0][c][i] = ddft[1][c][i] +
+          row / (height-1.0) * (ddft[2][c][i] - ddft[1][c][i]);
+    }
     pix = image[row*width];
     memcpy (prev, pix, sizeof prev);
     frow = row / (height-1.0) * (dim[2]-1);
@@ -5216,8 +5226,10 @@ void CLASS parse_mos (int offset)
 	strcpy (model, mod[i]);
     }
     if (!strcmp(data,"icc_camera_to_tone_matrix")) {
-      for (i=0; i < 9; i++)
-	romm_cam[0][i] = int_to_float(get4());
+      for (c=0; c < ARRAY_SIZE(romm_cam); c++) {
+	for (i=0; i < ARRAY_SIZE(romm_cam[0]); i++)
+	  romm_cam[c][i] = int_to_float(get4());
+      }
       romm_coeff (romm_cam);
     }
     if (!strcmp(data,"CaptProf_color_matrix")) {
@@ -6250,8 +6262,10 @@ void CLASS parse_phase_one (int base)
     switch (tag) {
       case 0x100:  flip = "0653"[data & 3]-'0';  break;
       case 0x106:
-	for (i=0; i < 9; i++)
-	  romm_cam[0][i] = getreal(11);
+	for (c=0; c < ARRAY_SIZE(romm_cam); c++) {
+	  for (i=0; i < ARRAY_SIZE(romm_cam[0]); i++)
+	    romm_cam[c][i] = getreal(11);
+	}
 	romm_coeff (romm_cam);
 	break;
       case 0x107:
@@ -7391,7 +7405,7 @@ void CLASS adobe_coeff (const char *make, const char *model)
   };
   double cam_xyz[4][3];
   char name[130];
-  int i, j;
+  int i, j, c;
 
   sprintf (name, "%s %s", make, model);
   for (i=0; i < sizeof table / sizeof *table; i++)
@@ -7399,8 +7413,10 @@ void CLASS adobe_coeff (const char *make, const char *model)
       if (table[i].black)   black   = (ushort) table[i].black;
       if (table[i].maximum) maximum = (ushort) table[i].maximum;
       if (table[i].trans[0]) {
-	for (j=0; j < 12; j++)
-	  cam_xyz[0][j] = table[i].trans[j] / 10000.0;
+	for (c=0; c < ARRAY_SIZE(cam_xyz); c++) {
+	  for (j=0; j < ARRAY_SIZE(cam_xyz[0]); j++)
+	    cam_xyz[c][j] = table[i].trans[c * ARRAY_SIZE(cam_xyz[0]) + j] / 10000.0;
+	}
 	cam_xyz_coeff (cam_xyz);
       }
       break;