From 9035efaa924c69f4f4fcb1049c7dc4f43b9da980 Mon Sep 17 00:00:00 2001 From: paul Date: Sun, 10 Oct 2004 11:56:56 +0000 Subject: 2004-10-10 Paul Jakma * version.h.in: (pid_output*) add const qualifier. * command.h: Change DEFUN func to take const char *[] rather than char **, to begin process of fixing compile warnings in lib/. Nearly all other changes in this commit follow from this change. * buffer.{c,h}: (buffer_write) pointer-arithmetic is gccism, take const void * and cast an automatic const char *p to it. (buffer_putstr) add const * command.c: (zencrypt) const qualifier (cmd_execute_command_real) ditto (cmd_execute_command_strict) ditto (config_log_file) ditto. Fix leak of getcwd() returned string. * memory.{c,h}: Add MTYPE_DISTRIBUTE_IFNAME for struct dist ifname. * distribute.{c,h}: Update with const qualifier. (distribute_free) use MTYPE_DISTRIBUTE_IFNAME (distribute_lookup) Cast to char *, note that it's ok. (distribute_hash_alloc) use MTYPE_DISTRIBUTE_IFNAME. (distribute_get) Cast to char *, note that it's ok. * filter.c: Update with const qualifier. * if.{c,h}: ditto. * if_rmap.{c,h}: ditto. (if_rmap_lookup) Cast to char *, note that it's ok. (if_rmap_get) ditto. * log.{c,h}: Update with const qualifier. * plist.{c,h}: ditto. * routemap.{c,h}: ditto. * smux.{c,h}: ditto. Fix some signed/unsigned comparisons. * sockopt.c: (getsockopt_cmsg_data) add return for error case. * vty.c: Update with const qualifier. --- lib/command.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index 2766a357..168fe563 100644 --- a/lib/command.c +++ b/lib/command.c @@ -432,7 +432,7 @@ to64(char *s, long v, int n) } } -char *zencrypt (char *passwd) +char *zencrypt (const char *passwd) { char salt[6]; struct timeval tv; @@ -1932,7 +1932,7 @@ cmd_execute_command_real (vector vline, struct vty *vty, struct cmd_element **cm struct cmd_element *matched_element; unsigned int matched_count, incomplete_count; int argc; - char *argv[CMD_ARGC_MAX]; + const char *argv[CMD_ARGC_MAX]; enum match_type match = 0; int varflag; char *command; @@ -2111,7 +2111,7 @@ cmd_execute_command_strict (vector vline, struct vty *vty, struct cmd_element *matched_element; unsigned int matched_count, incomplete_count; int argc; - char *argv[CMD_ARGC_MAX]; + const char *argv[CMD_ARGC_MAX]; int varflag; enum match_type match = 0; char *command; @@ -2983,22 +2983,38 @@ DEFUN (config_log_file, "Logging filename\n") { int ret; - char *cwd; - char *fullpath; - + char *p = NULL; + const char *fullpath; + /* Path detection. */ if (! IS_DIRECTORY_SEP (*argv[0])) { - cwd = getcwd (NULL, MAXPATHLEN); - fullpath = XMALLOC (MTYPE_TMP, - strlen (cwd) + strlen (argv[0]) + 2); - sprintf (fullpath, "%s/%s", cwd, argv[0]); + char cwd[MAXPATHLEN+1]; + cwd[MAXPATHLEN] = '\0'; + + if (getcwd (cwd, MAXPATHLEN) == NULL) + { + zlog_err ("config_log_file: Unable to alloc mem!"); + return CMD_WARNING; + } + + if ( (p = XMALLOC (MTYPE_TMP, strlen (cwd) + strlen (argv[0]) + 2)) + == NULL) + { + zlog_err ("config_log_file: Unable to alloc mem!"); + return CMD_WARNING; + } + sprintf (p, "%s/%s", cwd, argv[0]); + fullpath = p; } else fullpath = argv[0]; ret = zlog_set_file (NULL, ZLOG_FILE, fullpath); + if (p) + XFREE (MTYPE_TMP, p); + if (!ret) { vty_out (vty, "can't open logfile %s\n", argv[0]); -- cgit v1.2.1