This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository legacy-imlib2.

View the commit online.

commit d27354926a3dab93584b4c1988995eea512d6fe5
Author: Kim Woelders <k...@woelders.dk>
AuthorDate: Fri Jan 27 08:51:54 2023 +0100

    Loaders: Avoid cast-align warnings with -Wcast-align=strict
---
 src/lib/Imlib2_Loader.h          |  2 ++
 src/modules/loaders/loader_ani.c | 12 ++++++++----
 src/modules/loaders/loader_bmp.c |  4 ++--
 src/modules/loaders/loader_png.c |  9 ++++++---
 src/modules/loaders/loader_tga.c |  3 ++-
 5 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/lib/Imlib2_Loader.h b/src/lib/Imlib2_Loader.h
index 63f8637..ec0c36e 100644
--- a/src/lib/Imlib2_Loader.h
+++ b/src/lib/Imlib2_Loader.h
@@ -224,4 +224,6 @@ int                 decompress_load(ImlibImage * im, int load_data,
 
 #define QUIT_WITH_RC(_err) { rc = _err; goto quit; }
 
+#define PCAST(T, p) ((T)(const void *)(p))
+
 #endif /* IMLIB2_LOADER_H */
diff --git a/src/modules/loaders/loader_ani.c b/src/modules/loaders/loader_ani.c
index 034ba97..b436f46 100644
--- a/src/modules/loaders/loader_ani.c
+++ b/src/modules/loaders/loader_ani.c
@@ -28,7 +28,8 @@ static const char  *const _formats[] = { "ani" };
 typedef struct {
    unsigned char       nest;
    int                 nframes, nfsteps;
-   uint32_t           *rates, *seq;
+   const uint32_t     *rates;
+   const uint32_t     *seq;
 } riff_ctx_t;
 
 typedef struct {
@@ -119,7 +120,8 @@ _riff_parse(ImlibImage * im, riff_ctx_t * ctx, const char *fdata,
              break;
           }
 
-        chunk = (const ani_chunk_t *)fptr;
+        chunk = PCAST(const ani_chunk_t *, fptr);
+
         type = SWAP_LE_32(chunk->hdr.type);
         size = SWAP_LE_32(chunk->hdr.size);
 
@@ -202,7 +204,8 @@ _riff_parse(ImlibImage * im, riff_ctx_t * ctx, const char *fdata,
              pf->frame_delay = (1000 * SWAP_LE_32(AH.rate)) / 60;
              break;
           case RIFF_TYPE_rate:
-             ctx->rates = (uint32_t *) (fptr + 8);
+             ctx->rates = PCAST(const uint32_t *, fptr + 8);
+
              if ((int)size != 4 * ctx->nfsteps)
                {
                   D("rate chunk size mismatch: %d != %d\n", size,
@@ -216,7 +219,8 @@ _riff_parse(ImlibImage * im, riff_ctx_t * ctx, const char *fdata,
              Dx("\n");
              break;
           case RIFF_TYPE_seq:
-             ctx->seq = (uint32_t *) (fptr + 8);
+             ctx->seq = PCAST(const uint32_t *, fptr + 8);
+
              if ((int)size != 4 * ctx->nfsteps)
                {
                   D("seq chunk size mismatch: %d != %d\n", size,
diff --git a/src/modules/loaders/loader_bmp.c b/src/modules/loaders/loader_bmp.c
index 0ace8b6..c47363a 100644
--- a/src/modules/loaders/loader_bmp.c
+++ b/src/modules/loaders/loader_bmp.c
@@ -681,7 +681,7 @@ _load(ImlibImage * im, int load_data)
           {
              for (x = 0; x < w && buffer_ptr < buffer_end_safe; x++)
                {
-                  pixel = *(unsigned short *)buffer_ptr;
+                  pixel = *PCAST(const unsigned short *, buffer_ptr);
 
                   if (im->has_alpha)
                      a = SCALE(a, pixel);
@@ -730,7 +730,7 @@ _load(ImlibImage * im, int load_data)
           {
              for (x = 0; x < w && buffer_ptr < buffer_end_safe; x++)
                {
-                  pixel = *(unsigned int *)buffer_ptr;
+                  pixel = *PCAST(const unsigned int *, buffer_ptr);
 
                   if (im->has_alpha)
                      a = SCALE(a, pixel);
diff --git a/src/modules/loaders/loader_png.c b/src/modules/loaders/loader_png.c
index 9e58273..34c5b9b 100644
--- a/src/modules/loaders/loader_png.c
+++ b/src/modules/loaders/loader_png.c
@@ -244,7 +244,8 @@ row_callback(png_struct * png_ptr, png_byte * new_row,
            PNG_PASS_COLS(im->w, pass), PNG_PASS_ROWS(im->h, pass));
         y = y0 + dy * row_num;
 
-        sptr = (const uint32_t *)new_row;       /* Assuming aligned */
+        sptr = PCAST(const uint32_t *, new_row);        /* Assuming aligned */
+
         dptr = im->data + y * im->w;
         for (x = x0; x < im->w; x += dx)
           {
@@ -341,7 +342,8 @@ _load(ImlibImage * im, int load_data)
 
    for (ic = 0;; ic++, fptr += 8 + len + 4)
      {
-        chunk = (const png_chunk_t *)fptr;
+        chunk = PCAST(const png_chunk_t *, fptr);
+
         len = htonl(chunk->hdr.len);
         D("Scan %3d: %06lx: %6d: %.4s: ", ic,
           fptr - (unsigned char *)im->fi->fdata, len, chunk->hdr.name);
@@ -429,7 +431,8 @@ _load(ImlibImage * im, int load_data)
 
    for (ic = 0;; ic++, fptr += 8 + len + 4)
      {
-        chunk = (const png_chunk_t *)fptr;
+        chunk = PCAST(const png_chunk_t *, fptr);
+
         len = htonl(chunk->hdr.len);
         D("Chunk %3d: %06lx: %6d: %.4s: ", ic,
           fptr - (unsigned char *)im->fi->fdata, len, chunk->hdr.name);
diff --git a/src/modules/loaders/loader_tga.c b/src/modules/loaders/loader_tga.c
index e0312fa..1f97ba9 100644
--- a/src/modules/loaders/loader_tga.c
+++ b/src/modules/loaders/loader_tga.c
@@ -94,7 +94,8 @@ _load(ImlibImage * im, int load_data)
 
    if (im->fi->fsize > (int)(sizeof(tga_footer)))
      {
-        footer = (tga_footer *) (fptr + im->fi->fsize - sizeof(tga_footer));
+        footer =
+           PCAST(const tga_footer *, fptr + im->fi->fsize - sizeof(tga_footer));
 
         /* check the footer to see if we have a v2.0 TGA file */
         footer_present = memcmp(footer->signature, TGA_SIGNATURE,

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to