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

@@ -735,7 +735,7 @@ option_index(struct display *dp, const char *opt, size_t len)
static int
get_option(struct display *dp, const char *opt, int *value)
{
const png_byte i = option_index(dp, opt, strlen(opt));
png_byte i = option_index(dp, opt, strlen(opt));
if (dp->entry[i]) /* option was set on command line */
{
@@ -789,7 +789,7 @@ record_opt(struct display *dp, png_byte opt, const char *entry_name)
* numerical value.
*/
{
const unsigned int sp = dp->csp; /* stack entry of next searched option */
unsigned int sp = dp->csp; /* stack entry of next searched option */
if (sp >= dp->tsp)
{
@@ -797,7 +797,7 @@ record_opt(struct display *dp, png_byte opt, const char *entry_name)
* searched entry or the start of the dp->curr buffer if there is nothing
* on the stack yet (sp == 0).
*/
const int offset = set_opt_string_(dp, sp, opt, entry_name);
int offset = set_opt_string_(dp, sp, opt, entry_name);
if (sp > 0)
dp->stack[sp-1].opt_string_end = offset;
@@ -1222,7 +1222,7 @@ advance_opt(struct display *dp, png_byte opt, int search)
}
static int
getallopts_(struct display *dp, const png_byte opt, int *value, int record)
getallopts_(struct display *dp, png_byte opt, int *value, int record)
/* Like getop but iterate over all the values if the option was set to "all".
*/
{
@@ -1259,7 +1259,7 @@ getsearchopts(struct display *dp, const char *opt_str, int *value)
/* As above except that if the option was not set try a search */
{
png_byte istrat;
const png_byte opt = option_index(dp, opt_str, strlen(opt_str));
png_byte opt = option_index(dp, opt_str, strlen(opt_str));
int record = options[opt].search;
const char *entry_name;
@@ -2302,7 +2302,7 @@ cppng(struct display *dp, const char *file, const char *gv dest)
}
int
main(const int argc, const char * const * const argv)
main(int argc, char **argv)
{
/* For each file on the command line test it with a range of transforms */
int option_end;
@@ -2379,7 +2379,7 @@ main(const int argc, const char * const * const argv)
/* Here on any return, including failures, except user/internal issues
*/
{
const int pass = (d.options & STRICT) ?
int pass = (d.options & STRICT) ?
RESULT_STRICT(d.results) : RESULT_RELAXED(d.results);
if (!pass)