mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
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.
This commit is contained in:
parent
da109d3e6e
commit
7dacc4d5aa
6
png.c
6
png.c
@ -53,7 +53,7 @@ png_set_sig_bytes(png_structrp png_ptr, int num_bytes)
|
|||||||
int PNGAPI
|
int PNGAPI
|
||||||
png_sig_cmp(png_const_bytep sig, size_t start, size_t num_to_check)
|
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)
|
if (num_to_check > 8)
|
||||||
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;
|
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_STRING(string) pos = png_safecat(out, 29, pos, (string))
|
||||||
# define APPEND_NUMBER(format, value)\
|
# 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 */
|
if (num <= 0x80000000) /* else overflowed */
|
||||||
{
|
{
|
||||||
unsigned int ndigits = 0, first = 16 /* flag value */;
|
unsigned int ndigits = 0, first = 16 /* flag value */;
|
||||||
char digits[10];
|
char digits[10] = {0};
|
||||||
|
|
||||||
while (num)
|
while (num)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -255,7 +255,7 @@ void
|
|||||||
png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
|
png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
|
||||||
png_alloc_size_t value)
|
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));
|
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_alloc_size_t u;
|
||||||
png_charp str;
|
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: */
|
/* Avoid overflow by doing the negate in a png_alloc_size_t: */
|
||||||
u = (png_alloc_size_t)value;
|
u = (png_alloc_size_t)value;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user