From 06c0a71d2315756db874e98bc4f760ca3283b6a6 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Mon, 29 Jan 2007 22:51:44 +0000 Subject: preparatory patch for -Wwrite-strings #3 --- init/init.c | 16 ++++++++-------- loginutils/adduser.c | 4 ++-- loginutils/getty.c | 16 ++++++++-------- loginutils/passwd.c | 4 ++-- loginutils/su.c | 6 +++--- miscutils/crontab.c | 10 ++++------ util-linux/fdisk.c | 4 ++-- util-linux/fdisk_osf.c | 8 ++++---- util-linux/ipcrm.c | 8 ++++---- util-linux/mount.c | 10 +++++----- 10 files changed, 42 insertions(+), 44 deletions(-) diff --git a/init/init.c b/init/init.c index 7694b44..cb31400 100644 --- a/init/init.c +++ b/init/init.c @@ -326,27 +326,26 @@ static void console_init(void) /* Force the TERM setting to vt102 for serial console -- * if TERM is set to linux (the default) */ if (s == NULL || strcmp(s, "linux") == 0) - putenv("TERM=vt102"); + putenv((char*)"TERM=vt102"); #if !ENABLE_SYSLOGD log_console = console; #endif } else { if (s == NULL) - putenv("TERM=linux"); + putenv((char*)"TERM=linux"); } close(fd); } messageD(LOG, "console=%s", console); } -static void fixup_argv(int argc, char **argv, char *new_argv0) +static void fixup_argv(int argc, char **argv, const char *new_argv0) { int len; /* Fix up argv[0] to be certain we claim to be init */ len = strlen(argv[0]); - memset(argv[0], 0, len); - safe_strncpy(argv[0], new_argv0, len + 1); + strncpy(argv[0], new_argv0, len); /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */ len = 1; @@ -381,7 +380,8 @@ static pid_t run(const struct init_action *a) { int i; pid_t pid; - char *s, *tmpCmd, *cmd[INIT_BUFFS_SIZE], *cmdpath; + char *s, *tmpCmd, *cmdpath; + char *cmd[INIT_BUFFS_SIZE]; char buf[INIT_BUFFS_SIZE + 6]; /* INIT_BUFFS_SIZE+strlen("exec ")+1 */ sigset_t nmask, omask; static const char press_enter[] = @@ -389,7 +389,7 @@ static pid_t run(const struct init_action *a) #include CUSTOMIZED_BANNER #endif "\nPlease press Enter to activate this console. "; - char *prog; + const char *prog; /* Block sigchild while forking. */ sigemptyset(&nmask); @@ -472,7 +472,7 @@ static pid_t run(const struct init_action *a) /* See if any special /bin/sh requiring characters are present */ if (strpbrk(a->command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) { cmd[0] = (char *)DEFAULT_SHELL; - cmd[1] = "-c"; + cmd[1] = (char*)"-c"; cmd[2] = strcat(strcpy(buf, "exec "), a->command); cmd[3] = NULL; } else { diff --git a/loginutils/adduser.c b/loginutils/adduser.c index ea0b89a..5a48e9c 100644 --- a/loginutils/adduser.c +++ b/loginutils/adduser.c @@ -169,7 +169,7 @@ int adduser_main(int argc, char **argv) bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); } - pw.pw_gecos = "Linux User,,,"; + pw.pw_gecos = (char *)"Linux User,,,"; pw.pw_shell = (char *)DEFAULT_SHELL; pw.pw_dir = NULL; @@ -185,7 +185,7 @@ int adduser_main(int argc, char **argv) /* create a passwd struct */ pw.pw_name = argv[optind]; - pw.pw_passwd = "x"; + pw.pw_passwd = (char *)"x"; pw.pw_uid = 0; pw.pw_gid = usegroup ? xgroup2gid(usegroup) : 0; /* exits on failure */ diff --git a/loginutils/getty.c b/loginutils/getty.c index f2c2b4a..8f81caf 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c @@ -33,7 +33,7 @@ #include #if ENABLE_FEATURE_WTMP extern void updwtmp(const char *filename, const struct utmp *ut); -static void update_utmp(char *line); +static void update_utmp(const char *line); #endif #endif /* LOGIN_PROCESS */ @@ -85,10 +85,10 @@ static void update_utmp(char *line); struct options { int flags; /* toggle switches, see below */ unsigned timeout; /* time-out period */ - char *login; /* login program */ - char *tty; /* name of tty */ - char *initstring; /* modem init string */ - char *issue; /* alternative issue file */ + const char *login; /* login program */ + const char *tty; /* name of tty */ + const char *initstring; /* modem init string */ + const char *issue; /* alternative issue file */ int numspeed; /* number of baud rates to try */ int speeds[MAX_SPEED]; /* baud rates to be tried */ }; @@ -187,7 +187,7 @@ static void parse_args(int argc, char **argv, struct options *op) const char *p = op->initstring; char *q; - q = op->initstring = xstrdup(op->initstring); + op->initstring = q = xstrdup(op->initstring); /* copy optarg into op->initstring decoding \ddd octal codes into chars */ while (*p) { @@ -233,7 +233,7 @@ static void xdup2(int srcfd, int dstfd, const char *tty) } /* open_tty - set up tty as standard { input, output, error } */ -static void open_tty(char *tty, struct termios *tp, int local) +static void open_tty(const char *tty, struct termios *tp, int local) { int chdir_to_root = 0; @@ -655,7 +655,7 @@ static void termios_final(struct options *op, struct termios *tp, struct chardat #ifdef SYSV_STYLE #if ENABLE_FEATURE_UTMP /* update_utmp - update our utmp entry */ -static void update_utmp(char *line) +static void update_utmp(const char *line) { struct utmp ut; struct utmp *utp; diff --git a/loginutils/passwd.c b/loginutils/passwd.c index 5c822b1..ab20f28 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c @@ -53,7 +53,7 @@ static void crypt_make_salt(char *p, int cnt) static char* new_password(const struct passwd *pw, uid_t myuid, int algo) { char salt[sizeof("$N$XXXXXXXX")]; /* "$N$XXXXXXXX" or "XX" */ - char *orig = ""; + char *orig = (char*)""; char *newp = NULL; char *cipher = NULL; char *cp = NULL; @@ -241,7 +241,7 @@ int passwd_main(int argc, char **argv) /*STATE_ALGO_des = 0x20, not needed yet */ }; unsigned opt; - char *opt_a = ""; + const char *opt_a = ""; const char *filename; char *myname; char *name; diff --git a/loginutils/su.c b/loginutils/su.c index e1c1591..9a134dd 100644 --- a/loginutils/su.c +++ b/loginutils/su.c @@ -14,9 +14,9 @@ int su_main(int argc, char **argv) { unsigned flags; - char *opt_shell = 0; - char *opt_command = 0; - char *opt_username = "root"; + char *opt_shell = NULL; + char *opt_command = NULL; + const char *opt_username = "root"; struct passwd *pw; uid_t cur_uid = getuid(); const char *tty; diff --git a/miscutils/crontab.c b/miscutils/crontab.c index d442272..eb7c205 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c @@ -290,8 +290,7 @@ static void EditFile(const char *user, const char *file) /* * CHILD - change user and run editor */ - char *ptr; - char visual[1024]; + const char *ptr; if (ChangeUser(user, 1) < 0) exit(0); @@ -299,10 +298,9 @@ static void EditFile(const char *user, const char *file) if (ptr == NULL || strlen(ptr) > 256) ptr = PATH_VI; - snprintf(visual, sizeof(visual), "%s %s", ptr, file); - execl(DEFAULT_SHELL, DEFAULT_SHELL, "-c", visual, NULL); - perror("exec"); - exit(0); + ptr = xasprintf("%s %s", ptr, file); + execl(DEFAULT_SHELL, DEFAULT_SHELL, "-c", ptr, NULL); + bb_perror_msg_and_die("exec"); } if (pid < 0) { /* diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index f15b9af..6d82710 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c @@ -185,7 +185,7 @@ static void reread_partition_table(int leave); static void delete_partition(int i); static int get_partition(int warn, int max); static void list_types(const struct systypes *sys); -static unsigned read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, char *mesg); +static unsigned read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, const char *mesg); #endif static const char *partition_type(unsigned char type); static void fdisk_fatal(enum failure why) ATTRIBUTE_NORETURN; @@ -1410,7 +1410,7 @@ get_boot(enum action what) * There is no default if DFLT is not between LOW and HIGH. */ static unsigned -read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, char *mesg) +read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, const char *mesg) { unsigned i; int default_ok = 1; diff --git a/util-linux/fdisk_osf.c b/util-linux/fdisk_osf.c index 3f56bd2..2555c2e 100644 --- a/util-linux/fdisk_osf.c +++ b/util-linux/fdisk_osf.c @@ -630,7 +630,7 @@ xbsd_create_disklabel(void) } static int -edit_int(int def, char *mesg) +edit_int(int def, const char *mesg) { mesg = xasprintf("%s (%d): ", mesg, def); do { @@ -639,7 +639,7 @@ edit_int(int def, char *mesg) } while (!isdigit(*line_ptr)); def = atoi(line_ptr); ret: - free(mesg); + free((char*)mesg); return def; } @@ -707,9 +707,9 @@ sync_disks(void) static void xbsd_write_bootstrap(void) { - char *bootdir = BSD_LINUX_BOOTDIR; char path[MAXPATHLEN]; - char *dkbasename; + const char *bootdir = BSD_LINUX_BOOTDIR; + const char *dkbasename; struct xbsd_disklabel dl; char *d, *p, *e; int sector; diff --git a/util-linux/ipcrm.c b/util-linux/ipcrm.c index 507e58f..886c2ef 100644 --- a/util-linux/ipcrm.c +++ b/util-linux/ipcrm.c @@ -152,8 +152,8 @@ int ipcrm_main(int argc, char **argv) (c == 'm') ? shmget(key, 0, 0) : semget(key, 0, 0)); if (id < 0) { - char *errmsg; - const char * const what = "key"; + const char *errmsg; + const char *const what = "key"; error++; switch (errno) { @@ -183,8 +183,8 @@ int ipcrm_main(int argc, char **argv) semctl(id, 0, IPC_RMID, arg)); if (result) { - char *errmsg; - const char * const what = iskey ? "key" : "id"; + const char *errmsg; + const char *const what = iskey ? "key" : "id"; error++; switch (errno) { diff --git a/util-linux/mount.c b/util-linux/mount.c index ee45f01..ba98519 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -64,7 +64,7 @@ enum { * flags */ struct { - char *name; + const char *name; long flags; } static mount_options[] = { // MS_FLAGS set a bit. ~MS_FLAGS disable that bit. 0 flags are NOPs. @@ -122,7 +122,7 @@ struct { #define VECTOR_SIZE(v) (sizeof(v) / sizeof((v)[0])) /* Append mount options to string */ -static void append_mount_options(char **oldopts, char *newopts) +static void append_mount_options(char **oldopts, const char *newopts) { if (*oldopts && **oldopts) { /* do not insert options which are already there */ @@ -303,7 +303,7 @@ static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts) fsname = 0; if (!mp->mnt_type || !*mp->mnt_type) { /* bind mount */ mp->mnt_fsname = fsname = bb_simplify_path(mp->mnt_fsname); - mp->mnt_type = "bind"; + mp->mnt_type = (char*)"bind"; } mp->mnt_freq = mp->mnt_passno = 0; @@ -1342,7 +1342,7 @@ prepare_kernel_data: do_mount: /* perform actual mount */ - mp->mnt_type = "nfs"; + mp->mnt_type = (char*)"nfs"; retval = mount_it_now(mp, vfsflags, (char*)&data); goto ret; @@ -1428,7 +1428,7 @@ static int singlemount(struct mntent *mp, int ignore_busy) // lock is required vfsflags |= MS_MANDLOCK; - mp->mnt_type = "cifs"; + mp->mnt_type = (char*)"cifs"; rc = mount_it_now(mp, vfsflags, filteropts); if (ENABLE_FEATURE_CLEAN_UP) free(mp->mnt_fsname); goto report_error; -- cgit v1.1