Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ca210c

Browse files
authored
Merge pull request #16975 from vitalybuka/bounds
Fix "out of bounds" undefined behavior
2 parents 200380e + 1ad8efb commit 1ca210c

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

extern/agg24-svn/include/agg_pixfmt_gray.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,13 @@ namespace agg
136136
typedef typename color_type::calc_type calc_type;
137137
enum
138138
{
139-
num_components = 1,
140139
pix_width = sizeof(value_type) * Step,
141140
pix_step = Step,
142141
pix_offset = Offset,
143142
};
144143
struct pixel_type
145144
{
146-
value_type c[num_components];
145+
value_type c[pix_step];
147146

148147
void set(value_type v)
149148
{
@@ -167,22 +166,22 @@ namespace agg
167166

168167
pixel_type* next()
169168
{
170-
return (pixel_type*)(c + pix_step);
169+
return this + 1;
171170
}
172171

173172
const pixel_type* next() const
174173
{
175-
return (const pixel_type*)(c + pix_step);
174+
return this + 1;
176175
}
177176

178177
pixel_type* advance(int n)
179178
{
180-
return (pixel_type*)(c + n * pix_step);
179+
return this + n;
181180
}
182181

183182
const pixel_type* advance(int n) const
184183
{
185-
return (const pixel_type*)(c + n * pix_step);
184+
return this + n;
186185
}
187186
};
188187

extern/agg24-svn/include/agg_pixfmt_rgb.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,13 @@ namespace agg
192192
typedef typename color_type::calc_type calc_type;
193193
enum
194194
{
195-
num_components = 3,
196195
pix_step = Step,
197196
pix_offset = Offset,
198197
pix_width = sizeof(value_type) * pix_step
199198
};
200199
struct pixel_type
201200
{
202-
value_type c[num_components];
201+
value_type c[pix_step];
203202

204203
void set(value_type r, value_type g, value_type b)
205204
{
@@ -230,22 +229,22 @@ namespace agg
230229

231230
pixel_type* next()
232231
{
233-
return (pixel_type*)(c + pix_step);
232+
return this + 1;
234233
}
235234

236235
const pixel_type* next() const
237236
{
238-
return (const pixel_type*)(c + pix_step);
237+
return this + 1;
239238
}
240239

241240
pixel_type* advance(int n)
242241
{
243-
return (pixel_type*)(c + n * pix_step);
242+
return this + n;
244243
}
245244

246245
const pixel_type* advance(int n) const
247246
{
248-
return (const pixel_type*)(c + n * pix_step);
247+
return this + n;
249248
}
250249
};
251250

extern/agg24-svn/include/agg_pixfmt_rgba.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,13 +1515,12 @@ namespace agg
15151515
typedef typename color_type::calc_type calc_type;
15161516
enum
15171517
{
1518-
num_components = 4,
15191518
pix_step = 4,
15201519
pix_width = sizeof(value_type) * pix_step,
15211520
};
15221521
struct pixel_type
15231522
{
1524-
value_type c[num_components];
1523+
value_type c[pix_step];
15251524

15261525
void set(value_type r, value_type g, value_type b, value_type a)
15271526
{
@@ -1555,22 +1554,22 @@ namespace agg
15551554

15561555
pixel_type* next()
15571556
{
1558-
return (pixel_type*)(c + pix_step);
1557+
return this + 1;
15591558
}
15601559

15611560
const pixel_type* next() const
15621561
{
1563-
return (const pixel_type*)(c + pix_step);
1562+
return this + 1;
15641563
}
15651564

15661565
pixel_type* advance(int n)
15671566
{
1568-
return (pixel_type*)(c + n * pix_step);
1567+
return this + n;
15691568
}
15701569

15711570
const pixel_type* advance(int n) const
15721571
{
1573-
return (const pixel_type*)(c + n * pix_step);
1572+
return this + n;
15741573
}
15751574
};
15761575

@@ -2193,13 +2192,12 @@ namespace agg
21932192
typedef typename color_type::calc_type calc_type;
21942193
enum
21952194
{
2196-
num_components = 4,
21972195
pix_step = 4,
21982196
pix_width = sizeof(value_type) * pix_step,
21992197
};
22002198
struct pixel_type
22012199
{
2202-
value_type c[num_components];
2200+
value_type c[pix_step];
22032201

22042202
void set(value_type r, value_type g, value_type b, value_type a)
22052203
{
@@ -2233,22 +2231,22 @@ namespace agg
22332231

22342232
pixel_type* next()
22352233
{
2236-
return (pixel_type*)(c + pix_step);
2234+
return this + 1;
22372235
}
22382236

22392237
const pixel_type* next() const
22402238
{
2241-
return (const pixel_type*)(c + pix_step);
2239+
return this + 1;
22422240
}
22432241

22442242
pixel_type* advance(int n)
22452243
{
2246-
return (pixel_type*)(c + n * pix_step);
2244+
return this + n;
22472245
}
22482246

22492247
const pixel_type* advance(int n) const
22502248
{
2251-
return (const pixel_type*)(c + n * pix_step);
2249+
return this + n;
22522250
}
22532251
};
22542252

0 commit comments

Comments
 (0)