15bec5421Sopenharmony_cidiff --git a/arm/arm_init.c b/arm/arm_init.c
25bec5421Sopenharmony_ciindex ab22525b3..3a89998ab 100644
35bec5421Sopenharmony_ci--- a/arm/arm_init.c
45bec5421Sopenharmony_ci+++ b/arm/arm_init.c
55bec5421Sopenharmony_ci@@ -31,23 +31,21 @@
65bec5421Sopenharmony_ci  * has partial support is contrib/arm-neon/linux.c - a generic Linux
75bec5421Sopenharmony_ci  * implementation which reads /proc/cpufino.
85bec5421Sopenharmony_ci  */
95bec5421Sopenharmony_ci-#include <signal.h> /* for sig_atomic_t */
105bec5421Sopenharmony_ci-
115bec5421Sopenharmony_ci #ifndef PNG_ARM_NEON_FILE
125bec5421Sopenharmony_ci-#  if defined(__aarch64__) || defined(_M_ARM64)
135bec5421Sopenharmony_ci-     /* ARM Neon is expected to be unconditionally available on ARM64. */
145bec5421Sopenharmony_ci-#    error "PNG_ARM_NEON_CHECK_SUPPORTED must not be defined on this platform"
155bec5421Sopenharmony_ci-#  elif defined(__linux__)
165bec5421Sopenharmony_ci-#    define PNG_ARM_NEON_FILE "contrib/arm-neon/linux.c"
175bec5421Sopenharmony_ci-#  else
185bec5421Sopenharmony_ci-#    error "No support for run-time ARM Neon checking; use compile-time options"
195bec5421Sopenharmony_ci+#  ifdef __linux__
205bec5421Sopenharmony_ci+#     define PNG_ARM_NEON_FILE "contrib/arm-neon/linux.c"
215bec5421Sopenharmony_ci #  endif
225bec5421Sopenharmony_ci #endif
235bec5421Sopenharmony_ci 
245bec5421Sopenharmony_ci-static int png_have_neon(png_structp png_ptr);
255bec5421Sopenharmony_ci #ifdef PNG_ARM_NEON_FILE
265bec5421Sopenharmony_ci-#  include PNG_ARM_NEON_FILE
275bec5421Sopenharmony_ci-#endif
285bec5421Sopenharmony_ci+
295bec5421Sopenharmony_ci+#include <signal.h> /* for sig_atomic_t */
305bec5421Sopenharmony_ci+static int png_have_neon(png_structp png_ptr);
315bec5421Sopenharmony_ci+#include PNG_ARM_NEON_FILE
325bec5421Sopenharmony_ci+
335bec5421Sopenharmony_ci+#else  /* PNG_ARM_NEON_FILE */
345bec5421Sopenharmony_ci+#  error "PNG_ARM_NEON_FILE undefined: no support for run-time ARM NEON checks"
355bec5421Sopenharmony_ci+#endif /* PNG_ARM_NEON_FILE */
365bec5421Sopenharmony_ci #endif /* PNG_ARM_NEON_CHECK_SUPPORTED */
375bec5421Sopenharmony_ci 
385bec5421Sopenharmony_ci #ifndef PNG_ALIGNED_MEMORY_SUPPORTED
395bec5421Sopenharmony_cidiff --git a/arm/palette_neon_intrinsics.c b/arm/palette_neon_intrinsics.c
405bec5421Sopenharmony_ciindex 92c7d6f9f..49909d475 100644
415bec5421Sopenharmony_ci--- a/arm/palette_neon_intrinsics.c
425bec5421Sopenharmony_ci+++ b/arm/palette_neon_intrinsics.c
435bec5421Sopenharmony_ci@@ -65,12 +65,11 @@ png_do_expand_palette_rgba8_neon(png_structrp png_ptr, png_row_infop row_info,
445bec5421Sopenharmony_ci    png_uint_32 row_width = row_info->width;
455bec5421Sopenharmony_ci    const png_uint_32 *riffled_palette =
465bec5421Sopenharmony_ci       (const png_uint_32 *)png_ptr->riffled_palette;
475bec5421Sopenharmony_ci-   const png_uint_32 pixels_per_chunk = 4;
485bec5421Sopenharmony_ci-   png_uint_32 i;
495bec5421Sopenharmony_ci+   const png_int_32 pixels_per_chunk = 4;
505bec5421Sopenharmony_ci+   int i;
515bec5421Sopenharmony_ci 
525bec5421Sopenharmony_ci    png_debug(1, "in png_do_expand_palette_rgba8_neon");
535bec5421Sopenharmony_ci 
545bec5421Sopenharmony_ci-   PNG_UNUSED(row)
555bec5421Sopenharmony_ci    if (row_width < pixels_per_chunk)
565bec5421Sopenharmony_ci       return 0;
575bec5421Sopenharmony_ci 
585bec5421Sopenharmony_ci@@ -110,11 +109,10 @@ png_do_expand_palette_rgb8_neon(png_structrp png_ptr, png_row_infop row_info,
595bec5421Sopenharmony_ci    png_uint_32 row_width = row_info->width;
605bec5421Sopenharmony_ci    png_const_bytep palette = (png_const_bytep)png_ptr->palette;
615bec5421Sopenharmony_ci    const png_uint_32 pixels_per_chunk = 8;
625bec5421Sopenharmony_ci-   png_uint_32 i;
635bec5421Sopenharmony_ci+   int i;
645bec5421Sopenharmony_ci 
655bec5421Sopenharmony_ci    png_debug(1, "in png_do_expand_palette_rgb8_neon");
665bec5421Sopenharmony_ci 
675bec5421Sopenharmony_ci-   PNG_UNUSED(row)
685bec5421Sopenharmony_ci    if (row_width <= pixels_per_chunk)
695bec5421Sopenharmony_ci       return 0;
705bec5421Sopenharmony_ci 
715bec5421Sopenharmony_cidiff --git a/pngread.c b/pngread.c
725bec5421Sopenharmony_ciindex 5ab922403..8fa7d9f16 100644
735bec5421Sopenharmony_ci--- a/pngread.c
745bec5421Sopenharmony_ci+++ b/pngread.c
755bec5421Sopenharmony_ci@@ -3452,6 +3452,7 @@ png_image_read_background(png_voidp argument)
765bec5421Sopenharmony_ci 
775bec5421Sopenharmony_ci             for (pass = 0; pass < passes; ++pass)
785bec5421Sopenharmony_ci             {
795bec5421Sopenharmony_ci+               png_bytep row = png_voidcast(png_bytep, display->first_row);
805bec5421Sopenharmony_ci                unsigned int     startx, stepx, stepy;
815bec5421Sopenharmony_ci                png_uint_32      y;
825bec5421Sopenharmony_ci 
835bec5421Sopenharmony_ci@@ -3556,6 +3557,8 @@ png_image_read_background(png_voidp argument)
845bec5421Sopenharmony_ci 
855bec5421Sopenharmony_ci                         inrow += 2; /* gray and alpha channel */
865bec5421Sopenharmony_ci                      }
875bec5421Sopenharmony_ci+
885bec5421Sopenharmony_ci+                     row += display->row_bytes;
895bec5421Sopenharmony_ci                   }
905bec5421Sopenharmony_ci                }
915bec5421Sopenharmony_ci             }
925bec5421Sopenharmony_cidiff --git a/pngrutil.c b/pngrutil.c
935bec5421Sopenharmony_ciindex ca060dd15..9ac8ec11f 100644
945bec5421Sopenharmony_ci--- a/pngrutil.c
955bec5421Sopenharmony_ci+++ b/pngrutil.c
965bec5421Sopenharmony_ci@@ -2075,22 +2075,21 @@ png_handle_eXIf(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
975bec5421Sopenharmony_ci       png_byte buf[1];
985bec5421Sopenharmony_ci       png_crc_read(png_ptr, buf, 1);
995bec5421Sopenharmony_ci       info_ptr->eXIf_buf[i] = buf[0];
1005bec5421Sopenharmony_ci-      if (i == 1)
1015bec5421Sopenharmony_ci+      if (i == 1 && buf[0] != 'M' && buf[0] != 'I'
1025bec5421Sopenharmony_ci+                 && info_ptr->eXIf_buf[0] != buf[0])
1035bec5421Sopenharmony_ci       {
1045bec5421Sopenharmony_ci-         if ((buf[0] != 'M' && buf[0] != 'I') ||
1055bec5421Sopenharmony_ci-             (info_ptr->eXIf_buf[0] != buf[0]))
1065bec5421Sopenharmony_ci-         {
1075bec5421Sopenharmony_ci-            png_crc_finish(png_ptr, length - 2);
1085bec5421Sopenharmony_ci-            png_chunk_benign_error(png_ptr, "incorrect byte-order specifier");
1095bec5421Sopenharmony_ci-            png_free(png_ptr, info_ptr->eXIf_buf);
1105bec5421Sopenharmony_ci-            info_ptr->eXIf_buf = NULL;
1115bec5421Sopenharmony_ci-            return;
1125bec5421Sopenharmony_ci-         }
1135bec5421Sopenharmony_ci+         png_crc_finish(png_ptr, length);
1145bec5421Sopenharmony_ci+         png_chunk_benign_error(png_ptr, "incorrect byte-order specifier");
1155bec5421Sopenharmony_ci+         png_free(png_ptr, info_ptr->eXIf_buf);
1165bec5421Sopenharmony_ci+         info_ptr->eXIf_buf = NULL;
1175bec5421Sopenharmony_ci+         return;
1185bec5421Sopenharmony_ci       }
1195bec5421Sopenharmony_ci    }
1205bec5421Sopenharmony_ci 
1215bec5421Sopenharmony_ci-   if (png_crc_finish(png_ptr, 0) == 0)
1225bec5421Sopenharmony_ci-      png_set_eXIf_1(png_ptr, info_ptr, length, info_ptr->eXIf_buf);
1235bec5421Sopenharmony_ci+   if (png_crc_finish(png_ptr, 0) != 0)
1245bec5421Sopenharmony_ci+      return;
1255bec5421Sopenharmony_ci+
1265bec5421Sopenharmony_ci+   png_set_eXIf_1(png_ptr, info_ptr, length, info_ptr->eXIf_buf);
1275bec5421Sopenharmony_ci 
1285bec5421Sopenharmony_ci    png_free(png_ptr, info_ptr->eXIf_buf);
1295bec5421Sopenharmony_ci    info_ptr->eXIf_buf = NULL;
1305bec5421Sopenharmony_ci@@ -2126,9 +2125,8 @@ png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
1315bec5421Sopenharmony_ci 
1325bec5421Sopenharmony_ci    num = length / 2 ;
1335bec5421Sopenharmony_ci 
1345bec5421Sopenharmony_ci-   if (length != num * 2 ||
1355bec5421Sopenharmony_ci-       num != (unsigned int)png_ptr->num_palette ||
1365bec5421Sopenharmony_ci-       num > (unsigned int)PNG_MAX_PALETTE_LENGTH)
1375bec5421Sopenharmony_ci+   if (num != (unsigned int) png_ptr->num_palette ||
1385bec5421Sopenharmony_ci+       num > (unsigned int) PNG_MAX_PALETTE_LENGTH)
1395bec5421Sopenharmony_ci    {
1405bec5421Sopenharmony_ci       png_crc_finish(png_ptr, length);
1415bec5421Sopenharmony_ci       png_chunk_benign_error(png_ptr, "invalid");
1425bec5421Sopenharmony_ci@@ -4622,11 +4620,11 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
1435bec5421Sopenharmony_ci        */
1445bec5421Sopenharmony_ci       {
1455bec5421Sopenharmony_ci          png_bytep temp = png_ptr->big_row_buf + 32;
1465bec5421Sopenharmony_ci-         size_t extra = (size_t)temp & 0x0f;
1475bec5421Sopenharmony_ci+         int extra = (int)((temp - (png_bytep)0) & 0x0f);
1485bec5421Sopenharmony_ci          png_ptr->row_buf = temp - extra - 1/*filter byte*/;
1495bec5421Sopenharmony_ci 
1505bec5421Sopenharmony_ci          temp = png_ptr->big_prev_row + 32;
1515bec5421Sopenharmony_ci-         extra = (size_t)temp & 0x0f;
1525bec5421Sopenharmony_ci+         extra = (int)((temp - (png_bytep)0) & 0x0f);
1535bec5421Sopenharmony_ci          png_ptr->prev_row = temp - extra - 1/*filter byte*/;
1545bec5421Sopenharmony_ci       }
1555bec5421Sopenharmony_ci #else
1565bec5421Sopenharmony_cidiff --git a/pngset.c b/pngset.c
1575bec5421Sopenharmony_ciindex 8c372cf41..6444c0615 100644
1585bec5421Sopenharmony_ci--- a/pngset.c
1595bec5421Sopenharmony_ci+++ b/pngset.c
1605bec5421Sopenharmony_ci@@ -1019,9 +1019,6 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
1615bec5421Sopenharmony_ci           info_ptr->trans_alpha = png_voidcast(png_bytep,
1625bec5421Sopenharmony_ci               png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH));
1635bec5421Sopenharmony_ci           memcpy(info_ptr->trans_alpha, trans_alpha, (size_t)num_trans);
1645bec5421Sopenharmony_ci-
1655bec5421Sopenharmony_ci-          info_ptr->valid |= PNG_INFO_tRNS;
1665bec5421Sopenharmony_ci-          info_ptr->free_me |= PNG_FREE_TRNS;
1675bec5421Sopenharmony_ci        }
1685bec5421Sopenharmony_ci        png_ptr->trans_alpha = info_ptr->trans_alpha;
1695bec5421Sopenharmony_ci    }
1705bec5421Sopenharmony_cidiff --git a/pngwrite.c b/pngwrite.c
1715bec5421Sopenharmony_ciindex 06c45d16a..b9a0ca188 100644
1725bec5421Sopenharmony_ci--- a/pngwrite.c
1735bec5421Sopenharmony_ci+++ b/pngwrite.c
1745bec5421Sopenharmony_ci@@ -489,16 +489,6 @@ png_convert_from_time_t(png_timep ptime, time_t ttime)
1755bec5421Sopenharmony_ci    png_debug(1, "in png_convert_from_time_t");
1765bec5421Sopenharmony_ci 
1775bec5421Sopenharmony_ci    tbuf = gmtime(&ttime);
1785bec5421Sopenharmony_ci-   if (tbuf == NULL)
1795bec5421Sopenharmony_ci-   {
1805bec5421Sopenharmony_ci-      /* TODO: add a safe function which takes a png_ptr argument and raises
1815bec5421Sopenharmony_ci-       * a png_error if the ttime argument is invalid and the call to gmtime
1825bec5421Sopenharmony_ci-       * fails as a consequence.
1835bec5421Sopenharmony_ci-       */
1845bec5421Sopenharmony_ci-      memset(ptime, 0, sizeof(*ptime));
1855bec5421Sopenharmony_ci-      return;
1865bec5421Sopenharmony_ci-   }
1875bec5421Sopenharmony_ci-
1885bec5421Sopenharmony_ci    png_convert_from_struct_tm(ptime, tbuf);
1895bec5421Sopenharmony_ci }
1905bec5421Sopenharmony_ci #endif
191