[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
adding a few 'const's
From: |
Bruno Haible |
Subject: |
adding a few 'const's |
Date: |
Tue, 24 Oct 2006 14:30:42 +0200 |
User-agent: |
KMail/1.9.1 |
Hi,
Compiling coreutils-6.4 with gcc-4.1 and
./configure --prefix=/packages/gnu \
CPPFLAGS="-Wall -Wformat=2 -Wmissing-field-initializers
-Wmissing-format-attribute -Wpointer-arith -Wstrict-aliasing=2 -Wwrite-strings"
\
CFLAGS="-O2 -g -Wbad-function-cast -Wdeclaration-after-statement"
yields a few warnings. They point to places where the code readability and
robustness can be increased by a few consts.
------------------------------------------------------------------------------
getdate.c:2255: warning: passing argument 2 of 'yyerror' discards qualifiers
from pointer target type
getdate.c:2398: warning: passing argument 2 of 'yyerror' discards qualifiers
from pointer target type
* getdate.y (yyerror): Make second argument a 'const char *'.
*** getdate.y.bak 2006-09-14 11:53:58.000000000 +0200
--- getdate.y 2006-10-24 01:33:51.000000000 +0200
***************
*** 195,201 ****
union YYSTYPE;
static int yylex (union YYSTYPE *, parser_control *);
! static int yyerror (parser_control *, char *);
static long int time_zone_hhmm (textint, long int);
%}
--- 195,201 ----
union YYSTYPE;
static int yylex (union YYSTYPE *, parser_control *);
! static int yyerror (parser_control *, const char *);
static long int time_zone_hhmm (textint, long int);
%}
***************
*** 1106,1112 ****
/* Do nothing if the parser reports an error. */
static int
! yyerror (parser_control *pc ATTRIBUTE_UNUSED, char *s ATTRIBUTE_UNUSED)
{
return 0;
}
--- 1106,1112 ----
/* Do nothing if the parser reports an error. */
static int
! yyerror (parser_control *pc ATTRIBUTE_UNUSED, const char *s ATTRIBUTE_UNUSED)
{
return 0;
}
------------------------------------------------------------------------------
dircolors.c:258: warning: assignment discards qualifiers from pointer target
type
* dircolors.c (dc_parse_stream): Make 'term' a 'const char *'.
*** dircolors.c.bak 2006-10-22 18:54:15.000000000 +0200
--- dircolors.c 2006-10-24 02:00:54.000000000 +0200
***************
*** 246,252 ****
char *input_line = NULL;
size_t input_line_size = 0;
char const *line;
! char *term;
bool ok = true;
/* State for the parser. */
--- 246,252 ----
char *input_line = NULL;
size_t input_line_size = 0;
char const *line;
! const char *term;
bool ok = true;
/* State for the parser. */
------------------------------------------------------------------------------
cat.c:677: warning: assignment discards qualifiers from pointer target type
* cat.c (infile): Change type to 'const char *'.
*** cat.c.bak 2006-10-22 18:54:15.000000000 +0200
--- cat.c 2006-10-24 02:08:53.000000000 +0200
***************
*** 55,61 ****
char *program_name;
/* Name of input file. May be "-". */
! static char *infile;
/* Descriptor on which input file is open. */
static int input_desc;
--- 55,61 ----
char *program_name;
/* Name of input file. May be "-". */
! static const char *infile;
/* Descriptor on which input file is open. */
static int input_desc;
------------------------------------------------------------------------------
csplit.c:1342: warning: assignment discards qualifiers from pointer target type
* csplit.c (prefix): Change type to 'const char * volatile'.
*** csplit.c.bak 2006-10-22 18:54:15.000000000 +0200
--- csplit.c 2006-10-24 02:12:18.000000000 +0200
***************
*** 152,158 ****
static char * volatile filename_space = NULL;
/* Prefix part of output file names. */
! static char * volatile prefix = NULL;
/* Suffix part of output file names. */
static char * volatile suffix = NULL;
--- 152,158 ----
static char * volatile filename_space = NULL;
/* Prefix part of output file names. */
! static const char * volatile prefix = NULL;
/* Suffix part of output file names. */
static char * volatile suffix = NULL;
------------------------------------------------------------------------------
cut.c:866: warning: passing argument 1 of 'cut_file' discards qualifiers from
pointer target type
* cut.c (cut_file): Change type of argument to 'const char *'.
*** cut.c.bak 2006-10-22 18:54:15.000000000 +0200
--- cut.c 2006-10-24 02:13:41.000000000 +0200
***************
*** 702,708 ****
Return true if successful. */
static bool
! cut_file (char *file)
{
FILE *stream;
--- 702,708 ----
Return true if successful. */
static bool
! cut_file (const char *file)
{
FILE *stream;
------------------------------------------------------------------------------
fold.c:306: warning: passing argument 1 of 'fold_file' discards qualifiers from
pointer target type
* fold.c (fold_file): Change filename argument type to 'const char *'.
*** fold.c.bak 2006-10-22 18:54:15.000000000 +0200
--- fold.c 2006-10-24 02:15:28.000000000 +0200
***************
*** 122,128 ****
Return true if successful. */
static bool
! fold_file (char *filename, size_t width)
{
FILE *istream;
int c;
--- 122,128 ----
Return true if successful. */
static bool
! fold_file (const char *filename, size_t width)
{
FILE *istream;
int c;
------------------------------------------------------------------------------
nl.c:67: warning: initialization discards qualifiers from pointer target type
nl.c:70: warning: initialization discards qualifiers from pointer target type
nl.c:73: warning: initialization discards qualifiers from pointer target type
nl.c:96: warning: initialization discards qualifiers from pointer target type
* nl.c (body_type, header_type, footer_type, current_type,
separator_str): Change type to 'const char *'.
(build_type_arg): Change first argument type to 'const char **'.
*** nl.c.bak 2006-10-22 18:54:15.000000000 +0200
--- nl.c 2006-10-24 02:18:36.000000000 +0200
***************
*** 64,79 ****
char *program_name;
/* Format of body lines (-b). */
! static char *body_type = "t";
/* Format of header lines (-h). */
! static char *header_type = "n";
/* Format of footer lines (-f). */
! static char *footer_type = "n";
/* Format currently being used (body, header, or footer). */
! static char *current_type;
/* Regex for body lines to number (-bp). */
static struct re_pattern_buffer body_regex;
--- 64,79 ----
char *program_name;
/* Format of body lines (-b). */
! static const char *body_type = "t";
/* Format of header lines (-h). */
! static const char *header_type = "n";
/* Format of footer lines (-f). */
! static const char *footer_type = "n";
/* Format currently being used (body, header, or footer). */
! static const char *current_type;
/* Regex for body lines to number (-bp). */
static struct re_pattern_buffer body_regex;
***************
*** 93,99 ****
static struct re_pattern_buffer *current_regex = NULL;
/* Separator string to print after line number (-s). */
! static char *separator_str = "\t";
/* Input section delimiter string (-d). */
static char const *section_del = DEFAULT_SECTION_DELIMITERS;
--- 93,99 ----
static struct re_pattern_buffer *current_regex = NULL;
/* Separator string to print after line number (-s). */
! static const char *separator_str = "\t";
/* Input section delimiter string (-d). */
static char const *section_del = DEFAULT_SECTION_DELIMITERS;
***************
*** 235,241 ****
according to `optarg'. */
static bool
! build_type_arg (char **typep, struct re_pattern_buffer *regexp, char *fastmap)
{
const char *errmsg;
bool rval = true;
--- 235,242 ----
according to `optarg'. */
static bool
! build_type_arg (const char **typep,
! struct re_pattern_buffer *regexp, char *fastmap)
{
const char *errmsg;
bool rval = true;
------------------------------------------------------------------------------
paste.c:467: warning: assignment discards qualifiers from pointer target type
* paste.c (main): Avoid assigning a read-only string to 'optarg'.
*** paste.c.bak 2006-10-22 18:54:15.000000000 +0200
--- paste.c 2006-10-24 02:20:58.000000000 +0200
***************
*** 463,471 ****
{
case 'd':
/* Delimiter character(s). */
! if (optarg[0] == '\0')
! optarg = "\\0";
! delim_arg = optarg;
break;
case 's':
--- 463,469 ----
{
case 'd':
/* Delimiter character(s). */
! delim_arg = (optarg[0] == '\0' ? "\\0" : optarg);
break;
case 's':
------------------------------------------------------------------------------
pr.c:1367: warning: passing argument 1 of 'init_header' discards qualifiers
from pointer target type
pr.c:1387: warning: passing argument 1 of 'init_header' discards qualifiers
from pointer target type
* pr.c (init_header): Change filename argument type to 'const char *'.
*** pr.c.bak 2006-10-22 18:54:15.000000000 +0200
--- pr.c 2006-10-24 02:25:12.000000000 +0200
***************
*** 430,436 ****
void usage (int status);
static void print_files (int number_of_files, char **av);
static void init_parameters (int number_of_files);
! static void init_header (char *filename, int desc);
static bool init_fps (int number_of_files, char **av);
static void init_funcs (void);
static void init_store_cols (void);
--- 430,436 ----
void usage (int status);
static void print_files (int number_of_files, char **av);
static void init_parameters (int number_of_files);
! static void init_header (const char *filename, int desc);
static bool init_fps (int number_of_files, char **av);
static void init_funcs (void);
static void init_store_cols (void);
***************
*** 1653,1659 ****
FILENAME for reading. */
static void
! init_header (char *filename, int desc)
{
char *buf = NULL;
struct stat st;
--- 1653,1659 ----
FILENAME for reading. */
static void
! init_header (const char *filename, int desc)
{
char *buf = NULL;
struct stat st;
------------------------------------------------------------------------------
expr.c:457: warning: passing argument 1 of 'str_value' discards qualifiers from
pointer target type
expr.c:563: warning: passing argument 1 of 'str_value' discards qualifiers from
pointer target type
* expr.c (str_value): Change argument type to 'const char *'.
*** expr.c.bak 2006-10-22 18:54:15.000000000 +0200
--- expr.c 2006-10-24 02:29:21.000000000 +0200
***************
*** 236,242 ****
/* Return a VALUE for S. */
static VALUE *
! str_value (char *s)
{
VALUE *v = xmalloc (sizeof *v);
v->type = string;
--- 236,242 ----
/* Return a VALUE for S. */
static VALUE *
! str_value (const char *s)
{
VALUE *v = xmalloc (sizeof *v);
v->type = string;
------------------------------------------------------------------------------
printf.c:80: warning: initialization discards qualifiers from pointer target
type
* printf.c (cfcc_msg): Change type to 'const char * const'.
*** printf.c.bak 2006-10-22 18:54:15.000000000 +0200
--- printf.c 2006-10-24 02:30:30.000000000 +0200
***************
*** 76,82 ****
/* This message appears in N_() here rather than just in _() below because
the sole use would have been in a #define. */
! static char *const cfcc_msg =
N_("warning: %s: character(s) following character constant have been
ignored");
/* The name this program was run with. */
--- 76,82 ----
/* This message appears in N_() here rather than just in _() below because
the sole use would have been in a #define. */
! static const char *const cfcc_msg =
N_("warning: %s: character(s) following character constant have been
ignored");
/* The name this program was run with. */
------------------------------------------------------------------------------
tac.c:439: warning: assignment discards qualifiers from pointer target type
tac.c:584: warning: assignment discards qualifiers from pointer target type
* tac.c (separator): Change type to 'const char *'.
(copy_to_temp): Likewise for 'tempdir'.
*** tac.c.bak 2006-10-22 18:54:15.000000000 +0200
--- tac.c 2006-10-24 02:33:38.000000000 +0200
***************
*** 78,84 ****
char *program_name;
/* The string that separates the records of the file. */
! static char *separator;
/* True if we have ever read standard input. */
static bool have_read_stdin = false;
--- 78,84 ----
char *program_name;
/* The string that separates the records of the file. */
! static const char *separator;
/* True if we have ever read standard input. */
static bool have_read_stdin = false;
***************
*** 426,432 ****
copy_to_temp (FILE **g_tmp, char **g_tempfile, int input_fd, char const *file)
{
static char *template = NULL;
! static char *tempdir;
char *tempfile;
FILE *tmp;
int fd;
--- 426,432 ----
copy_to_temp (FILE **g_tmp, char **g_tempfile, int input_fd, char const *file)
{
static char *template = NULL;
! static const char *tempdir;
char *tempfile;
FILE *tmp;
int fd;
------------------------------------------------------------------------------
tail.c:298: warning: return discards qualifiers from pointer target type
* tail.c (pretty_name): Change return type to 'const char *'.
*** tail.c.bak 2006-10-22 18:54:15.000000000 +0200
--- tail.c 2006-10-24 02:35:10.000000000 +0200
***************
*** 292,298 ****
return ((f->fd == -1) ^ (f->errnum == 0));
}
! static char *
pretty_name (struct File_spec const *f)
{
return (STREQ (f->name, "-") ? "standard input" : f->name);
--- 292,298 ----
return ((f->fd == -1) ^ (f->errnum == 0));
}
! static const char *
pretty_name (struct File_spec const *f)
{
return (STREQ (f->name, "-") ? "standard input" : f->name);
------------------------------------------------------------------------------
tr.c:610: warning: assignment discards qualifiers from pointer target type
tr.c:613: warning: assignment discards qualifiers from pointer target type
tr.c:616: warning: assignment discards qualifiers from pointer target type
tr.c:619: warning: assignment discards qualifiers from pointer target type
tr.c:622: warning: assignment discards qualifiers from pointer target type
tr.c:625: warning: assignment discards qualifiers from pointer target type
tr.c:628: warning: assignment discards qualifiers from pointer target type
tr.c:631: warning: assignment discards qualifiers from pointer target type
* tr.c (make_printable_str): Change type of 'tmp` variable to
'const char *'.
*** tr.c.bak 2006-10-22 18:54:15.000000000 +0200
--- tr.c 2006-10-24 02:36:41.000000000 +0200
***************
*** 601,607 ****
for (i = 0; i < len; i++)
{
char buf[5];
! char *tmp = NULL;
unsigned char c = s[i];
switch (c)
--- 601,607 ----
for (i = 0; i < len; i++)
{
char buf[5];
! const char *tmp = NULL;
unsigned char c = s[i];
switch (c)
------------------------------------------------------------------------------
Bruno
- adding a few 'const's,
Bruno Haible <=