From 84322a684945a9b40c0caad67ad9194d8f873f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20K=C3=B6ppe?= Date: Mon, 27 Apr 2020 16:53:30 +0100 Subject: [PATCH] [agg24]: Fix bad pointer arithmetic The array c is an array of value_type[4], and thus its initial pointer cannot be arbitrarily advanced (without causing undefined behaviour). What seems to be desired instead is to consider the _containing_ object as a member of an array and perform arithmetic in _that_ array. This can be done by _first_ computing the pointer to the ambient object. --- extern/agg24-svn/include/agg_pixfmt_rgba.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extern/agg24-svn/include/agg_pixfmt_rgba.h b/extern/agg24-svn/include/agg_pixfmt_rgba.h index 701ccad6ef6a..cb249949f3ad 100644 --- a/extern/agg24-svn/include/agg_pixfmt_rgba.h +++ b/extern/agg24-svn/include/agg_pixfmt_rgba.h @@ -1555,22 +1555,22 @@ namespace agg pixel_type* next() { - return (pixel_type*)(c + pix_step); + return reinterpret_cast(c) + 1; } const pixel_type* next() const { - return (const pixel_type*)(c + pix_step); + return reinterpret_cast(c) + 1; } pixel_type* advance(int n) { - return (pixel_type*)(c + n * pix_step); + return reinterpret_cast(c) + n; } const pixel_type* advance(int n) const { - return (const pixel_type*)(c + n * pix_step); + return reinterpret_cast(c) + n; } }; @@ -2233,22 +2233,22 @@ namespace agg pixel_type* next() { - return (pixel_type*)(c + pix_step); + return reinterpret_cast(c) + 1; } const pixel_type* next() const { - return (const pixel_type*)(c + pix_step); + return reinterpret_cast(c) + 1; } pixel_type* advance(int n) { - return (pixel_type*)(c + n * pix_step); + return reinterpret_cast(c) + n; } const pixel_type* advance(int n) const { - return (const pixel_type*)(c + n * pix_step); + return reinterpret_cast(c) + n; } };