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

@@ -2986,7 +2986,6 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
*/
static int
png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
{
int rgb_error = 0;
@@ -2995,12 +2994,11 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
if ((row_info->color_type & PNG_COLOR_MASK_PALETTE) == 0 &&
(row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
{
const png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
const png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
const png_uint_32 bc = 32768 - rc - gc;
const png_uint_32 row_width = row_info->width;
const int have_alpha =
(row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0;
png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
png_uint_32 bc = 32768 - rc - gc;
png_uint_32 row_width = row_info->width;
int have_alpha = (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0;
if (row_info->bit_depth == 8)
{
@@ -4143,12 +4141,11 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
{
if (row_info->bit_depth == 8)
{
const png_bytep table = png_ptr->gamma_from_1;
png_bytep table = png_ptr->gamma_from_1;
if (table != NULL)
{
const int step =
(row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2;
int step = (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2;
/* The alpha channel is the last component: */
row += step - 1;
@@ -4162,13 +4159,12 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
else if (row_info->bit_depth == 16)
{
const png_uint_16pp table = png_ptr->gamma_16_from_1;
const int gamma_shift = png_ptr->gamma_shift;
png_uint_16pp table = png_ptr->gamma_16_from_1;
int gamma_shift = png_ptr->gamma_shift;
if (table != NULL)
{
const int step =
(row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4;
int step = (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4;
/* The alpha channel is the last component: */
row += step - 2;