Changeset d427f08 for cmd.c


Ignore:
Timestamp:
Jun 22, 2011, 3:40:50 PM (10 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
b343c2c
Parents:
84a071f
git-author:
Jason Gross <jgross@mit.edu> (06/06/11 05:24:30)
git-committer:
Nelson Elhage <nelhage@mit.edu> (06/22/11 15:40:50)
Message:
Use G_GNUC_WARN_UNUSED_RESULT

Have gcc warn us when we ignore the result of a function that requires
the caller to free the result, or an initilization function that can
fail.  This might help (slightly) with preventing leaks and segfaults.

Additionally changed some functions that should never fail to not
return values.  (The owl_list_* functions changed only fail if
list->size < 0, which we assume is not the case elsewhere.)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cmd.c

    raad166a rd427f08  
    99/**************************************************************************/
    1010
    11 int owl_cmddict_setup(owl_cmddict *cd) {
     11void owl_cmddict_setup(owl_cmddict *cd)
     12{
    1213  owl_cmddict_init(cd);
    13   return owl_cmd_add_defaults(cd);
     14  owl_cmd_add_defaults(cd);
    1415}
    1516
     
    1920
    2021/* for bulk initialization at startup */
    21 int owl_cmddict_add_from_list(owl_cmddict *cd, const owl_cmd *cmds) {
     22void owl_cmddict_add_from_list(owl_cmddict *cd, const owl_cmd *cmds)
     23{
    2224  const owl_cmd *cur;
    23   int ret = 0;
    2425  for (cur = cmds; cur->name != NULL; cur++) {
    25     ret = owl_cmddict_add_cmd(cd, cur);
    26     if (ret < 0) break;
    27   }
    28   return ret;
     26    owl_cmddict_add_cmd(cd, cur);
     27  }
    2928}
    3029
     
    3837
    3938/* creates a new command alias */
    40 int owl_cmddict_add_alias(owl_cmddict *cd, const char *alias_from, const char *alias_to) {
     39void owl_cmddict_add_alias(owl_cmddict *cd, const char *alias_from, const char *alias_to) {
    4140  owl_cmd *cmd;
    4241  cmd = g_new(owl_cmd, 1);
     
    4443  owl_perlconfig_new_command(cmd->name);
    4544  owl_dict_insert_element(cd, cmd->name, cmd, (void (*)(void *))owl_cmd_delete);
    46   return(0);
    4745}
    4846
     
    5755}
    5856
    59 char *_owl_cmddict_execute(const owl_cmddict *cd, const owl_context *ctx, const char *const *argv, int argc, const char *buff) {
     57/* caller must free the return */
     58G_GNUC_WARN_UNUSED_RESULT char *_owl_cmddict_execute(const owl_cmddict *cd, const owl_context *ctx, const char *const *argv, int argc, const char *buff)
     59{
    6060  char *retval = NULL;
    6161  const owl_cmd *cmd;
     
    7272}
    7373
    74 char *owl_cmddict_execute(const owl_cmddict *cd, const owl_context *ctx, const char *cmdbuff) {
     74/* caller must free the return */
     75G_GNUC_WARN_UNUSED_RESULT char *owl_cmddict_execute(const owl_cmddict *cd, const owl_context *ctx, const char *cmdbuff)
     76{
    7577  char **argv;
    7678  int argc;
     
    9496}
    9597
    96 char *owl_cmddict_execute_argv(const owl_cmddict *cd, const owl_context *ctx, const char *const *argv, int argc) {
     98/* caller must free the return */
     99G_GNUC_WARN_UNUSED_RESULT char *owl_cmddict_execute_argv(const owl_cmddict *cd, const owl_context *ctx, const char *const *argv, int argc)
     100{
    97101  char *buff;
    98102  char *retval = NULL;
     
    121125}
    122126
    123 int owl_cmd_create_alias(owl_cmd *cmd, const char *name, const char *aliased_to) {
     127void owl_cmd_create_alias(owl_cmd *cmd, const char *name, const char *aliased_to) {
    124128  memset(cmd, 0, sizeof(owl_cmd));
    125129  cmd->name = g_strdup(name);
    126130  cmd->cmd_aliased_to = g_strdup(aliased_to);
    127131  cmd->summary = g_strdup_printf("%s%s", OWL_CMD_ALIAS_SUMMARY_PREFIX, aliased_to);
    128   return(0);
    129132}
    130133
     
    150153}
    151154
    152 char *owl_cmd_execute(const owl_cmd *cmd, const owl_cmddict *cd, const owl_context *ctx, int argc, const char *const *argv, const char *cmdbuff) {
     155/* caller must free the result */
     156G_GNUC_WARN_UNUSED_RESULT char *owl_cmd_execute(const owl_cmd *cmd, const owl_cmddict *cd, const owl_context *ctx, int argc, const char *const *argv, const char *cmdbuff)
     157{
    153158  static int alias_recurse_depth = 0;
    154159  int ival=0;
     
    223228
    224229/* returns a summary line describing this keymap.  the caller must free. */
    225 char *owl_cmd_describe(const owl_cmd *cmd) {
     230G_GNUC_WARN_UNUSED_RESULT char *owl_cmd_describe(const owl_cmd *cmd)
     231{
    226232  if (!cmd || !cmd->name || !cmd->summary) return NULL;
    227233  return g_strdup_printf("%-25s - %s", cmd->name, cmd->summary);
Note: See TracChangeset for help on using the changeset viewer.