From 7dacc4d5aa8253c1746f8de046492694b4b1e173 Mon Sep 17 00:00:00 2001 From: Cosmin Truta Date: Wed, 17 Jan 2024 16:59:38 +0200 Subject: [PATCH] Rewrite various initializations for the benefit of various compilers Mark the initialization of `png_signature[]` as static const inside the function `png_sig_cmp`. This might be helpful to optimizing compilers. Initialize the arrays `number_buf[]`, `digits[]` and `buffer[]` inside the functions `png_convert_to_rfc1123_buffer`, `png_ascii_from_fixed`, `png_warning_parameter_unsigned` and `png_warning_parameter_signed`. Although these initializations are redundant, compilers such as gcc-13 fail to see the redundancy. --- png.c | 6 +++--- pngerror.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/png.c b/png.c index 1bcf042af..9cc560e6c 100644 --- a/png.c +++ b/png.c @@ -53,7 +53,7 @@ png_set_sig_bytes(png_structrp png_ptr, int num_bytes) int PNGAPI png_sig_cmp(png_const_bytep sig, size_t start, size_t num_to_check) { - png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; + static const png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; if (num_to_check > 8) num_to_check = 8; @@ -731,7 +731,7 @@ png_convert_to_rfc1123_buffer(char out[29], png_const_timep ptime) { size_t pos = 0; - char number_buf[5]; /* enough for a four-digit year */ + char number_buf[5] = {0, 0, 0, 0, 0}; /* enough for a four-digit year */ # define APPEND_STRING(string) pos = png_safecat(out, 29, pos, (string)) # define APPEND_NUMBER(format, value)\ @@ -3218,7 +3218,7 @@ png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii, if (num <= 0x80000000) /* else overflowed */ { unsigned int ndigits = 0, first = 16 /* flag value */; - char digits[10]; + char digits[10] = {0}; while (num) { diff --git a/pngerror.c b/pngerror.c index ec3a709b9..53e79bacb 100644 --- a/pngerror.c +++ b/pngerror.c @@ -255,7 +255,7 @@ void png_warning_parameter_unsigned(png_warning_parameters p, int number, int format, png_alloc_size_t value) { - char buffer[PNG_NUMBER_BUFFER_SIZE]; + char buffer[PNG_NUMBER_BUFFER_SIZE] = {0}; png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value)); } @@ -265,7 +265,7 @@ png_warning_parameter_signed(png_warning_parameters p, int number, int format, { png_alloc_size_t u; png_charp str; - char buffer[PNG_NUMBER_BUFFER_SIZE]; + char buffer[PNG_NUMBER_BUFFER_SIZE] = {0}; /* Avoid overflow by doing the negate in a png_alloc_size_t: */ u = (png_alloc_size_t)value;