Changeset 46288ee in mainline


Ignore:
Timestamp:
2019-06-26T17:51:50Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b781cc49
Parents:
e62f8e3
Message:

Improvement alias/unlias according to feedback

This commit will change the behaviour of unalias
when a not existing aliasname is given. The command
will newly return CMD_FAILURE and print a failure message.
Existings aliases will be deleted.

When updating an existing alias with the command alias,
then the old data structure will only be freed when
str_dup did not fail. This will prevent the data
of being corrupted in case of a memory failure.

Location:
uspace/app/bdsh/cmds/modules
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/alias/alias.c

    re62f8e3 r46288ee  
    7272                /* update existing value */
    7373                alias_t *data = odict_get_instance(alias_link, alias_t, odict);
    74                 free(data->value);
    75                 data->value = str_dup(value);
     74                char *dup_value = str_dup(value);
    7675
    77                 if (data->value == NULL) {
     76                if (dup_value == NULL) {
    7877                        cli_error(CL_ENOMEM, "%s: failing to allocate memory for value\n", cmdname);
    7978                        return ENOMEM;
    8079                }
     80
     81                free(data->value);
     82                data->value = dup_value;
    8183        } else {
    8284                /* add new value */
  • uspace/app/bdsh/cmds/modules/unalias/unalias.c

    re62f8e3 r46288ee  
    9292        }
    9393
     94        int rc = CMD_SUCCESS;
    9495        size_t i;
    9596        for (i = 1; argv[i] != NULL; i++) {
     
    9899                if (alias_link == NULL) {
    99100                        cli_error(CL_ENOENT, "%s: No alias '%s' found\n", cmdname, argv[i]);
     101                        rc = CMD_FAILURE;
    100102                } else {
    101103                        free_alias(alias_link);
     
    103105        }
    104106
    105         return CMD_SUCCESS;
     107        return rc;
    106108}
Note: See TracChangeset for help on using the changeset viewer.