Remove top-level const from function-scope variables

As per the const correctness rules, top-level const-ness of data
in automatic scopes does not propagate outside of these scopes
(unlike const-ness at lower levels, such as pointers to const data).

Previously, const was used liberally, but inconsistently across the
libpng codebase. Using const wherever applicable is not incorrect.
However, _consistent_ use of const is difficult to maintain in such
conditions.

In conclusion, we shall continue to use const only where doing so is
strictly necessary:

1. If a function guarantees that it will not modify an argument
   passed by pointer, the corresponding function parameter should be
   a pointer-to-const (const T *).

2. Static data should not be modified, therefore it should be const.

Reference:
Google C++ Style Guide
https://google.github.io/styleguide/cppguide.html#Use_of_const
This commit is contained in:
Cosmin Truta
2018-08-18 22:47:16 -04:00
parent 1ef8882814
commit ceb327789b
22 changed files with 196 additions and 205 deletions

View File

@@ -2346,8 +2346,8 @@ static int
logpixel(const Transform *transform, png_uint_32 x, png_uint_32 y,
const Pixel *in, const Pixel *calc, const Pixel *out, const char *reason)
{
const png_uint_32 in_format = transform->in_image->image.format;
const png_uint_32 out_format = transform->out_image->image.format;
png_uint_32 in_format = transform->in_image->image.format;
png_uint_32 out_format = transform->out_image->image.format;
png_uint_32 back_format = out_format & ~PNG_FORMAT_FLAG_ALPHA;
const char *via_linear = "";
@@ -2602,12 +2602,12 @@ compare_two_images(Image *a, Image *b, int via_linear,
ptrdiff_t strideb = b->stride;
png_const_bytep rowa = a->buffer+16;
png_const_bytep rowb = b->buffer+16;
const png_uint_32 width = a->image.width;
const png_uint_32 height = a->image.height;
const png_uint_32 formata = a->image.format;
const png_uint_32 formatb = b->image.format;
const unsigned int a_sample = PNG_IMAGE_SAMPLE_SIZE(formata);
const unsigned int b_sample = PNG_IMAGE_SAMPLE_SIZE(formatb);
png_uint_32 width = a->image.width;
png_uint_32 height = a->image.height;
png_uint_32 formata = a->image.format;
png_uint_32 formatb = b->image.format;
unsigned int a_sample = PNG_IMAGE_SAMPLE_SIZE(formata);
unsigned int b_sample = PNG_IMAGE_SAMPLE_SIZE(formatb);
int alpha_added, alpha_removed;
int bchannels;
png_uint_32 y;
@@ -2790,8 +2790,7 @@ compare_two_images(Image *a, Image *b, int via_linear,
(formata & (formatb ^ PNG_FORMAT_FLAG_COLOR) & PNG_FORMAT_FLAG_COLOR)))
{
/* Was an alpha channel changed? */
const png_uint_32 alpha_changed = (formata ^ formatb) &
PNG_FORMAT_FLAG_ALPHA;
png_uint_32 alpha_changed = (formata ^ formatb) & PNG_FORMAT_FLAG_ALPHA;
/* Was an alpha channel removed? (The third test.) If so the direct
* comparison is only possible if the input alpha is opaque.
@@ -3627,7 +3626,7 @@ main(int argc, char **argv)
if (arg[0] == '-')
{
const int term = (arg[1] == '0' ? 0 : '\n');
int term = (arg[1] == '0' ? 0 : '\n');
unsigned int ich = 0;
/* Loop reading files, use a static buffer to simplify this and just