Fix: lttng: poptGetArg doesn't provide string ownership
[lttng-tools.git] / src / bin / lttng / commands / help.c
index 6e80571e3b05f00d1017664f3c21457a9b312e4e..bf5b603bd313ae99924c99f2911b96ab88555efa 100644 (file)
@@ -1,18 +1,8 @@
 /*
- * Copyright (C) 2015 Philippe Proulx <pproulx@efficios.com>
+ * Copyright (C) 2015 Philippe Proulx <pproulx@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2 only,
- * as published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _LGPL_SOURCE
 #include "../command.h"
 #include <common/utils.h>
 
-static const char *help_msg =
 #ifdef LTTNG_EMBED_HELP
+static const char *help_msg =
 #include <lttng-help.1.h>
-#else
-NULL
-#endif
 ;
+#endif
 
 static const char *lttng_help_msg =
 #ifdef LTTNG_EMBED_HELP
@@ -59,7 +47,7 @@ static struct poptOption long_options[] = {
 int cmd_help(int argc, const char **argv, const struct cmd_struct commands[])
 {
        int opt, ret = CMD_SUCCESS;
-       char *cmd_name;
+       const char *arg_cmd_name;
        static poptContext pc;
        const struct cmd_struct *cmd;
        int found = 0;
@@ -83,9 +71,8 @@ int cmd_help(int argc, const char **argv, const struct cmd_struct commands[])
        }
 
        /* Get command name */
-       cmd_name = (char *) poptGetArg(pc);
-
-       if (cmd_name == NULL) {
+       arg_cmd_name = poptGetArg(pc);
+       if (arg_cmd_name == NULL) {
                /* Fall back to lttng(1) */
                ret = utils_show_help(1, "lttng", lttng_help_msg);
                if (ret) {
@@ -98,7 +85,7 @@ int cmd_help(int argc, const char **argv, const struct cmd_struct commands[])
        }
 
        /* Help about help? */
-       if (strcmp(cmd_name, "help") == 0) {
+       if (strcmp(arg_cmd_name, "help") == 0) {
                SHOW_HELP();
                goto end;
        }
@@ -107,7 +94,7 @@ int cmd_help(int argc, const char **argv, const struct cmd_struct commands[])
        cmd = &commands[0];
 
        while (cmd->name != NULL) {
-               if (strcmp(cmd->name, cmd_name) == 0) {
+               if (strcmp(cmd->name, arg_cmd_name) == 0) {
                        found = 1;
                        break;
                }
@@ -116,7 +103,7 @@ int cmd_help(int argc, const char **argv, const struct cmd_struct commands[])
        }
 
        if (!found) {
-               ERR("Unknown command \"%s\"", cmd_name);
+               ERR("Unknown command \"%s\"", arg_cmd_name);
                ret = CMD_ERROR;
                goto end;
        }
This page took 0.024314 seconds and 4 git commands to generate.