Skip to content

Commit

Permalink
commands: allow <cmd>_aliases[] to be const
Browse files Browse the repository at this point in the history
Commands with aliases define an array of alias strings such as:

  static const char *<cmd>_aliases[] = { "<alias1>", NULL};

Although the elements are of type `const char *`, the elements
themselves are not `const`-qualified.  If the array is declared as:

  static const char * const <cmd>_aliases[] = { "<alias1>", NULL};

then the compiler warns about const qualifiers being discarded.  This is
because the `aliases` member of `struct command` is declared as `const
char *aliases;`.

Change the declaration of the `aliases` member of `struct command` to
`const char * const *aliases;` so that it can point to a `const` array
of `const char *`.  Also change the declaration of the `aliases`
variable in `register_command()` to avoid unnecessary type casts.

Signed-off-by: Ian Abbott <[email protected]>
Signed-off-by: Sascha Hauer <[email protected]>
  • Loading branch information
ian-abbott authored and saschahauer committed May 19, 2017
1 parent 495111d commit f6652e7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int register_command(struct command *cmd)
list_add_sort(&cmd->list, &command_list, compare);

if (cmd->aliases) {
char **aliases = (char**)cmd->aliases;
const char * const *aliases = cmd->aliases;
while(*aliases) {
struct command *c = xzalloc(sizeof(struct command));

Expand Down
2 changes: 1 addition & 1 deletion include/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct string_list;
*/
struct command {
const char *name; /* Command Name */
const char **aliases;
const char * const *aliases;
/* Implementation function */
int (*cmd)(int, char *[]);
int (*complete)(struct string_list *sl, char *instr);
Expand Down

0 comments on commit f6652e7

Please sign in to comment.