Re: [PATCH 3/5] mkfs: constify various strings

Darrick J. Wong
2020-10-15T05:31:54Z

On Thu, Oct 15, 2020 at 02:29:23PM +1100, Dave Chinner wrote:
> From: Dave Chinner <dchinner@redhat.com>
>
> Because the ini parser uses const strings and so the opt parsing
> needs to be told about it to avoid compiler warnings.
>
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
> ---
> include/linux.h | 2 +-
> mkfs/xfs_mkfs.c | 28 ++++++++++++++--------------
> 2 files changed, 15 insertions(+), 15 deletions(-)
>
> diff --git a/include/linux.h b/include/linux.h
> index 57726bb12b74..03b3278bb895 100644
> --- a/include/linux.h
> +++ b/include/linux.h
> @@ -92,7 +92,7 @@ static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
> uuid_unparse(*uu, buffer);
> }
>
> -static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu)
> +static __inline__ int platform_uuid_parse(const char *buffer, uuid_t *uu)
> {
> return uuid_parse(buffer, *uu);
> }
> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> index e84be74fb100..99ce0dc48d3b 100644
> --- a/mkfs/xfs_mkfs.c
> +++ b/mkfs/xfs_mkfs.c
> @@ -975,8 +975,8 @@ respec(
>
> static void
> unknown(
> - char opt,
> - char *s)
> + const char opt,
> + const char *s)
> {
> fprintf(stderr, _("unknown option -%c %s\n"), opt, s);
> usage();
> @@ -1387,7 +1387,7 @@ getnum(
> */
> static char *
> getstr(
> - char *str,
> + const char *str,
> struct opt_params *opts,
> int index)
> {
> @@ -1396,14 +1396,14 @@ getstr(
> /* empty strings for string options are not valid */
> if (!str || *str == '\0')
> reqval(opts->name, opts->subopts, index);
> - return str;
> + return (char *)str;

Hmm do any of the getstr callers actually change the return value?

Er... holy $bovine you have to change a lot of stuff everywhere to make
the const stick.

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> }
>
> static int
> block_opts_parser(
> struct opt_params *opts,
> int subopt,
> - char *value,
> + const char *value,
> struct cli_params *cli)
> {
> switch (subopt) {
> @@ -1420,7 +1420,7 @@ static int
> cfgfile_opts_parser(
> struct opt_params *opts,
> int subopt,
> - char *value,
> + const char *value,
> struct cli_params *cli)
> {
> switch (subopt) {
> @@ -1437,7 +1437,7 @@ static int
> data_opts_parser(
> struct opt_params *opts,
> int subopt,
> - char *value,
> + const char *value,
> struct cli_params *cli)
> {
> switch (subopt) {
> @@ -1506,7 +1506,7 @@ static int
> inode_opts_parser(
> struct opt_params *opts,
> int subopt,
> - char *value,
> + const char *value,
> struct cli_params *cli)
> {
> switch (subopt) {
> @@ -1541,7 +1541,7 @@ static int
> log_opts_parser(
> struct opt_params *opts,
> int subopt,
> - char *value,
> + const char *value,
> struct cli_params *cli)
> {
> switch (subopt) {
> @@ -1587,7 +1587,7 @@ static int
> meta_opts_parser(
> struct opt_params *opts,
> int subopt,
> - char *value,
> + const char *value,
> struct cli_params *cli)
> {
> switch (subopt) {
> @@ -1621,7 +1621,7 @@ static int
> naming_opts_parser(
> struct opt_params *opts,
> int subopt,
> - char *value,
> + const char *value,
> struct cli_params *cli)
> {
> switch (subopt) {
> @@ -1650,7 +1650,7 @@ static int
> rtdev_opts_parser(
> struct opt_params *opts,
> int subopt,
> - char *value,
> + const char *value,
> struct cli_params *cli)
> {
> switch (subopt) {
> @@ -1680,7 +1680,7 @@ static int
> sector_opts_parser(
> struct opt_params *opts,
> int subopt,
> - char *value,
> + const char *value,
> struct cli_params *cli)
> {
> switch (subopt) {
> @@ -1700,7 +1700,7 @@ static struct subopts {
> struct opt_params *opts;
> int (*parser)(struct opt_params *opts,
> int subopt,
> - char *value,
> + const char *value,
> struct cli_params *cli);
> } subopt_tab[] = {
> { 'b', &bopts, block_opts_parser },
> --
> 2.28.0
>