preparatory patch for -Wwrite-strings #1

This commit is contained in:
Denis Vlasenko 2007-01-29 22:51:00 +00:00
parent e935602ff5
commit a41fdf331a
17 changed files with 59 additions and 52 deletions

View File

@ -106,7 +106,7 @@ static char *get_trimmed_slice(char *s, char *e)
} }
#define parse_error(x) { err=x; goto pe_label; } #define parse_error(x) do { errmsg = x; goto pe_label; } while(0)
/* Don't depend on the tools to combine strings. */ /* Don't depend on the tools to combine strings. */
static const char config_file[] = CONFIG_FILE; static const char config_file[] = CONFIG_FILE;
@ -130,7 +130,7 @@ static void parse_config_file(void)
struct BB_suid_config *sct; struct BB_suid_config *sct;
struct BB_applet *applet; struct BB_applet *applet;
FILE *f; FILE *f;
char *err; const char *errmsg;
char *s; char *s;
char *e; char *e;
int i, lc, section; int i, lc, section;
@ -307,7 +307,7 @@ static void parse_config_file(void)
pe_label: pe_label:
fprintf(stderr, "Parse error in %s, line %d: %s\n", fprintf(stderr, "Parse error in %s, line %d: %s\n",
config_file, lc, err); config_file, lc, errmsg);
fclose(f); fclose(f);
/* Release any allocated memory before returning. */ /* Release any allocated memory before returning. */

View File

@ -504,7 +504,7 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
int gzipDataPipe[2] = { -1, -1 }; int gzipDataPipe[2] = { -1, -1 };
int gzipStatusPipe[2] = { -1, -1 }; int gzipStatusPipe[2] = { -1, -1 };
volatile int vfork_exec_errno = 0; volatile int vfork_exec_errno = 0;
char *zip_exec = (gzip == 1) ? "gzip" : "bzip2"; const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0) if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0)
bb_perror_msg_and_die("pipe"); bb_perror_msg_and_die("pipe");

View File

@ -14,7 +14,7 @@
int bb_cat(char **argv) int bb_cat(char **argv)
{ {
static char *const argv_dash[] = { "-", NULL }; static const char *const argv_dash[] = { "-", NULL };
FILE *f; FILE *f;
int retval = EXIT_SUCCESS; int retval = EXIT_SUCCESS;

View File

@ -41,7 +41,7 @@ static void xputenv(char *s)
static void maybe_set_utc(int opt) static void maybe_set_utc(int opt)
{ {
if (opt & DATE_OPT_UTC) if (opt & DATE_OPT_UTC)
xputenv("TZ=UTC0"); xputenv((char*)"TZ=UTC0");
} }
int date_main(int argc, char **argv) int date_main(int argc, char **argv)
@ -218,7 +218,7 @@ format_utc:
i = 22; i = 22;
goto format_utc; goto format_utc;
} else /* default case */ } else /* default case */
date_fmt = "%a %b %e %H:%M:%S %Z %Y"; date_fmt = (char*)"%a %b %e %H:%M:%S %Z %Y";
} }
if (*date_fmt == '\0') { if (*date_fmt == '\0') {
@ -228,7 +228,7 @@ format_utc:
/* Handle special conversions */ /* Handle special conversions */
if (strncmp(date_fmt, "%f", 2) == 0) { if (strncmp(date_fmt, "%f", 2) == 0) {
date_fmt = "%Y.%m.%d-%H:%M:%S"; date_fmt = (char*)"%Y.%m.%d-%H:%M:%S";
} }
/* Generate output string */ /* Generate output string */

View File

@ -222,7 +222,7 @@ int du_main(int argc, char **argv)
/* go through remaining args (if any) */ /* go through remaining args (if any) */
argv += optind; argv += optind;
if (optind >= argc) { if (optind >= argc) {
*--argv = "."; *--argv = (char*)".";
if (slink_depth == 1) { if (slink_depth == 1) {
slink_depth = 0; slink_depth = 0;
} }

View File

@ -67,8 +67,8 @@ static char **args;
static VALUE *docolon(VALUE * sv, VALUE * pv); static VALUE *docolon(VALUE * sv, VALUE * pv);
static VALUE *eval(void); static VALUE *eval(void);
static VALUE *int_value(arith_t i); static VALUE *int_value(arith_t i);
static VALUE *str_value(char *s); static VALUE *str_value(const char *s);
static int nextarg(char *str); static int nextarg(const char *str);
static int null(VALUE * v); static int null(VALUE * v);
static int toarith(VALUE * v); static int toarith(VALUE * v);
static void freev(VALUE * v); static void freev(VALUE * v);
@ -110,7 +110,7 @@ static VALUE *int_value(arith_t i)
/* Return a VALUE for S. */ /* Return a VALUE for S. */
static VALUE *str_value(char *s) static VALUE *str_value(const char *s)
{ {
VALUE *v; VALUE *v;
@ -172,7 +172,7 @@ static int toarith(VALUE * v)
/* Return nonzero if the next token matches STR exactly. /* Return nonzero if the next token matches STR exactly.
STR must not be NULL. */ STR must not be NULL. */
static int nextarg(char *str) static int nextarg(const char *str)
{ {
if (*args == NULL) if (*args == NULL)
return 0; return 0;

View File

@ -66,7 +66,7 @@ int fold_main(int argc, char **argv)
argv += optind; argv += optind;
if (!*argv) { if (!*argv) {
*--argv = "-"; *--argv = (char*)"-";
} }
do { do {

View File

@ -92,7 +92,7 @@ int head_main(int argc, char **argv)
argv += optind; argv += optind;
if (!*argv) { if (!*argv) {
*--argv = "-"; *--argv = (char*)"-";
} }
fmt = header_fmt_str + 1; fmt = header_fmt_str + 1;

View File

@ -26,7 +26,7 @@ int ln_main(int argc, char **argv)
char *last; char *last;
char *src_name; char *src_name;
char *src; char *src;
char *suffix = "~"; char *suffix = (char*)"~";
struct stat statbuf; struct stat statbuf;
int (*link_func)(const char *, const char *); int (*link_func)(const char *, const char *);

View File

@ -102,7 +102,7 @@ int md5_sha1_sum_main(int argc, char **argv)
} }
if (argc == optind) { if (argc == optind) {
argv[argc++] = "-"; argv[argc++] = (char*)"-";
} }
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) { if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) {

View File

@ -42,11 +42,11 @@
static int print_formatted(char *format, int argc, char **argv); static int print_formatted(char *format, int argc, char **argv);
static void print_direc(char *start, size_t length, static void print_direc(char *start, size_t length,
int field_width, int precision, char *argument); int field_width, int precision, const char *argument);
typedef void (*converter)(char *arg, void *result); typedef void (*converter)(const char *arg, void *result);
static void multiconvert(char *arg, void *result, converter convert) static void multiconvert(const char *arg, void *result, converter convert)
{ {
char s[16]; char s[16];
if (*arg == '"' || *arg == '\'') { if (*arg == '"' || *arg == '\'') {
@ -58,15 +58,15 @@ static void multiconvert(char *arg, void *result, converter convert)
fputs(arg, stderr); fputs(arg, stderr);
} }
static void conv_strtoul(char *arg, void *result) static void conv_strtoul(const char *arg, void *result)
{ {
*(unsigned long*)result = bb_strtoul(arg, NULL, 10); *(unsigned long*)result = bb_strtoul(arg, NULL, 10);
} }
static void conv_strtol(char *arg, void *result) static void conv_strtol(const char *arg, void *result)
{ {
*(long*)result = bb_strtol(arg, NULL, 10); *(long*)result = bb_strtol(arg, NULL, 10);
} }
static void conv_strtod(char *arg, void *result) static void conv_strtod(const char *arg, void *result)
{ {
char *end; char *end;
/* Well, this one allows leading whitespace... so what */ /* Well, this one allows leading whitespace... so what */
@ -75,21 +75,21 @@ static void conv_strtod(char *arg, void *result)
if (end[0]) errno = ERANGE; if (end[0]) errno = ERANGE;
} }
static unsigned long my_xstrtoul(char *arg) static unsigned long my_xstrtoul(const char *arg)
{ {
unsigned long result; unsigned long result;
multiconvert(arg, &result, conv_strtoul); multiconvert(arg, &result, conv_strtoul);
return result; return result;
} }
static long my_xstrtol(char *arg) static long my_xstrtol(const char *arg)
{ {
long result; long result;
multiconvert(arg, &result, conv_strtol); multiconvert(arg, &result, conv_strtol);
return result; return result;
} }
static double my_xstrtod(char *arg) static double my_xstrtod(const char *arg)
{ {
double result; double result;
multiconvert(arg, &result, conv_strtod); multiconvert(arg, &result, conv_strtod);
@ -239,7 +239,7 @@ static int print_formatted(char *format, int argc, char **argv)
static void static void
print_direc(char *start, size_t length, int field_width, int precision, print_direc(char *start, size_t length, int field_width, int precision,
char *argument) const char *argument)
{ {
char *p; /* Null-terminated copy of % directive. */ char *p; /* Null-terminated copy of % directive. */

View File

@ -91,7 +91,7 @@ int tail_main(int argc, char **argv)
if (argc >= 2 && (argv[1][0] == '+' || argv[1][0] == '-') if (argc >= 2 && (argv[1][0] == '+' || argv[1][0] == '-')
&& isdigit(argv[1][1]) && isdigit(argv[1][1])
) { ) {
argv[0] = "-n"; argv[0] = (char*)"-n";
argv--; argv--;
argc++; argc++;
} }

View File

@ -22,7 +22,7 @@ int yes_main(int argc, char **argv)
const char *fmt; const char *fmt;
char **first_arg; char **first_arg;
*argv = "y"; *argv = (char*)"y";
if (argc != 1) { if (argc != 1) {
++argv; ++argv;
} }

View File

@ -47,7 +47,7 @@ typedef struct var_s {
typedef struct chain_s { typedef struct chain_s {
struct node_s *first; struct node_s *first;
struct node_s *last; struct node_s *last;
char *programname; const char *programname;
} chain; } chain;
/* Function */ /* Function */
@ -399,7 +399,7 @@ static int nextrec, nextfile;
static node *break_ptr, *continue_ptr; static node *break_ptr, *continue_ptr;
static rstream *iF; static rstream *iF;
static xhash *vhash, *ahash, *fdhash, *fnhash; static xhash *vhash, *ahash, *fdhash, *fnhash;
static char *programname; static const char *programname;
static short lineno; static short lineno;
static int is_f0_split; static int is_f0_split;
static int nfields; static int nfields;
@ -703,7 +703,7 @@ static var *setvar_i(var *v, double value)
return v; return v;
} }
static char *getvar_s(var *v) static const char *getvar_s(var *v)
{ {
/* if v is numeric and has no cached string, convert it to string */ /* if v is numeric and has no cached string, convert it to string */
if ((v->type & (VF_NUMBER | VF_CACHED)) == VF_NUMBER) { if ((v->type & (VF_NUMBER | VF_CACHED)) == VF_NUMBER) {
@ -995,7 +995,7 @@ static node *new_node(uint32_t info)
return n; return n;
} }
static node *mk_re_node(char *s, node *n, regex_t *re) static node *mk_re_node(const char *s, node *n, regex_t *re)
{ {
n->info = OC_REGEXP; n->info = OC_REGEXP;
n->l.re = re; n->l.re = re;
@ -1347,7 +1347,7 @@ static void parse_program(char *p)
/* -------- program execution part -------- */ /* -------- program execution part -------- */
static node *mk_splitter(char *s, tsplitter *spl) static node *mk_splitter(const char *s, tsplitter *spl)
{ {
regex_t *re, *ire; regex_t *re, *ire;
node *n; node *n;
@ -1375,7 +1375,7 @@ static node *mk_splitter(char *s, tsplitter *spl)
static regex_t *as_regex(node *op, regex_t *preg) static regex_t *as_regex(node *op, regex_t *preg)
{ {
var *v; var *v;
char *s; const char *s;
if ((op->info & OPCLSMASK) == OC_REGEXP) { if ((op->info & OPCLSMASK) == OC_REGEXP) {
return icase ? op->r.ire : op->l.re; return icase ? op->r.ire : op->l.re;
@ -1419,7 +1419,7 @@ static void fsrealloc(int size)
nfields = size; nfields = size;
} }
static int awk_split(char *s, node *spl, char **slist) static int awk_split(const char *s, node *spl, char **slist)
{ {
int l, n = 0; int l, n = 0;
char c[4]; char c[4];
@ -1427,7 +1427,8 @@ static int awk_split(char *s, node *spl, char **slist)
regmatch_t pmatch[2]; regmatch_t pmatch[2];
/* in worst case, each char would be a separate field */ /* in worst case, each char would be a separate field */
*slist = s1 = xstrndup(s, strlen(s) * 2 + 3); *slist = s1 = xzalloc(strlen(s) * 2 + 3);
strcpy(s1, s);
c[0] = c[1] = (char)spl->info; c[0] = c[1] = (char)spl->info;
c[2] = c[3] = '\0'; c[2] = c[3] = '\0';
@ -1436,8 +1437,9 @@ static int awk_split(char *s, node *spl, char **slist)
if ((spl->info & OPCLSMASK) == OC_REGEXP) { /* regex split */ if ((spl->info & OPCLSMASK) == OC_REGEXP) { /* regex split */
while (*s) { while (*s) {
l = strcspn(s, c+2); l = strcspn(s, c+2);
if (regexec(icase ? spl->r.ire : spl->l.re, s, 1, pmatch, 0) == 0 && if (regexec(icase ? spl->r.ire : spl->l.re, s, 1, pmatch, 0) == 0
pmatch[0].rm_so <= l) { && pmatch[0].rm_so <= l
) {
l = pmatch[0].rm_so; l = pmatch[0].rm_so;
if (pmatch[0].rm_eo == 0) { l++; pmatch[0].rm_eo++; } if (pmatch[0].rm_eo == 0) { l++; pmatch[0].rm_eo++; }
} else { } else {
@ -1510,7 +1512,8 @@ static void split_f0(void)
static void handle_special(var *v) static void handle_special(var *v)
{ {
int n; int n;
char *b, *sep, *s; char *b;
const char *sep, *s;
int sl, l, len, i, bsize; int sl, l, len, i, bsize;
if (!(v->type & VF_SPECIAL)) if (!(v->type & VF_SPECIAL))
@ -1737,7 +1740,8 @@ static int fmt_num(char *b, int size, const char *format, double n, int int_as_i
static char *awk_printf(node *n) static char *awk_printf(node *n)
{ {
char *b = NULL; char *b = NULL;
char *fmt, *s, *s1, *f; char *fmt, *s, *f;
const char *s1;
int i, j, incr, bsize; int i, j, incr, bsize;
char c, c1; char c, c1;
var *v, *arg; var *v, *arg;
@ -1793,10 +1797,11 @@ static char *awk_printf(node *n)
* all matches. If src or dst is NULL, use $0. If ex=TRUE, enable * all matches. If src or dst is NULL, use $0. If ex=TRUE, enable
* subexpression matching (\1-\9) * subexpression matching (\1-\9)
*/ */
static int awk_sub(node *rn, char *repl, int nm, var *src, var *dest, int ex) static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int ex)
{ {
char *ds = NULL; char *ds = NULL;
char *sp, *s; const char *s;
const char *sp;
int c, i, j, di, rl, so, eo, nbs, n, dssize; int c, i, j, di, rl, so, eo, nbs, n, dssize;
regmatch_t pmatch[10]; regmatch_t pmatch[10];
regex_t sreg, *re; regex_t sreg, *re;
@ -1865,7 +1870,7 @@ static var *exec_builtin(node *op, var *res)
var *tv; var *tv;
node *an[4]; node *an[4];
var *av[4]; var *av[4];
char *as[4]; const char *as[4];
regmatch_t pmatch[2]; regmatch_t pmatch[2];
regex_t sreg, *re; regex_t sreg, *re;
static tsplitter tspl; static tsplitter tspl;
@ -1998,8 +2003,10 @@ static var *exec_builtin(node *op, var *res)
tt = getvar_i(av[1]); tt = getvar_i(av[1]);
else else
time(&tt); time(&tt);
s = (nargs > 0) ? as[0] : "%a %b %d %H:%M:%S %Z %Y"; //s = (nargs > 0) ? as[0] : "%a %b %d %H:%M:%S %Z %Y";
i = strftime(buf, MAXVARFMT, s, localtime(&tt)); i = strftime(buf, MAXVARFMT,
((nargs > 0) ? as[0] : "%a %b %d %H:%M:%S %Z %Y"),
localtime(&tt));
buf[i] = '\0'; buf[i] = '\0';
setvar_s(res, buf); setvar_s(res, buf);
break; break;
@ -2054,7 +2061,7 @@ static var *evaluate(node *op, var *res)
var *v1; var *v1;
union { union {
var *v; var *v;
char *s; const char *s;
double d; double d;
int i; int i;
} L, R; } L, R;
@ -2168,7 +2175,7 @@ static var *evaluate(node *op, var *res)
} else { /* OC_PRINTF */ } else { /* OC_PRINTF */
L.s = awk_printf(op1); L.s = awk_printf(op1);
fputs(L.s, X.F); fputs(L.s, X.F);
free(L.s); free((char*)L.s);
} }
fflush(X.F); fflush(X.F);
break; break;
@ -2610,7 +2617,7 @@ static rstream *next_input_file(void)
{ {
static rstream rsm; static rstream rsm;
FILE *F = NULL; FILE *F = NULL;
char *fname, *ind; const char *fname, *ind;
static int files_happen = FALSE; static int files_happen = FALSE;
if (rsm.F) fclose(rsm.F); if (rsm.F) fclose(rsm.F);

View File

@ -401,7 +401,7 @@ static void subCommand(const char * cmd, int num1, int num2)
if (cp) if (cp)
*cp++ = '\0'; *cp++ = '\0';
else else
cp = ""; cp = (char*)"";
while (*cp) switch (*cp++) { while (*cp) switch (*cp++) {
case 'g': case 'g':

View File

@ -239,7 +239,7 @@ extern int recursive_action(const char *fileName, int recurse,
void* userData, int depth); void* userData, int depth);
extern int device_open(const char *device, int mode); extern int device_open(const char *device, int mode);
extern int get_console_fd(void); extern int get_console_fd(void);
extern char *find_block_device(char *path); extern char *find_block_device(const char *path);
/* bb_copyfd_XX print read/write errors and return -1 if they occur */ /* bb_copyfd_XX print read/write errors and return -1 if they occur */
extern off_t bb_copyfd_eof(int fd1, int fd2); extern off_t bb_copyfd_eof(int fd1, int fd2);
extern off_t bb_copyfd_size(int fd1, int fd2, off_t size); extern off_t bb_copyfd_size(int fd1, int fd2, off_t size);

View File

@ -9,7 +9,7 @@
#include "libbb.h" #include "libbb.h"
char *find_block_device(char *path) char *find_block_device(const char *path)
{ {
DIR *dir; DIR *dir;
struct dirent *entry; struct dirent *entry;