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

Skip to content

Commit 676a257

Browse files
committed
Fix "out of bounds" undefined behavior
This is detected with clang and -fsanitizer=bounds. Out-of-bound addressing array of fixed size is undefined behavior in both C and C++. It is so even if underlying memory is properly allocated. Easy fix here is to iterate with this pointer instead of pixel_type::c array.
1 parent 2632ac9 commit 676a257

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

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)