summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.in4
-rw-r--r--docs/ChangeLog65
-rw-r--r--include/manconfig.h.in3
-rw-r--r--lib/tempfile.c12
-rw-r--r--libdb/db_ver.c12
-rw-r--r--src/accessdb.c2
-rw-r--r--src/catman.c47
-rw-r--r--src/check_mandirs.c9
-rw-r--r--src/filenames.c2
-rw-r--r--src/filenames.h2
-rw-r--r--src/globbing.c4
-rw-r--r--src/lexgrog.l10
-rw-r--r--src/man.c88
-rw-r--r--src/man.h2
-rw-r--r--src/mandb.c6
-rw-r--r--src/manp.c13
-rw-r--r--src/manp.h4
-rw-r--r--src/manpath.c10
-rw-r--r--src/whatis.c10
-rw-r--r--zsoelim/zsoelim.l4
20 files changed, 192 insertions, 117 deletions
diff --git a/configure.in b/configure.in
index 0bcea63d..30a7a302 100644
--- a/configure.in
+++ b/configure.in
@@ -100,6 +100,10 @@ dnl
AC_PROG_CC
AC_PROG_CPP
CFLAGS="$CFLAGS -Wall"
+if test "$GCC" = yes
+then
+ CFLAGS="$CFLAGS -Wwrite-strings"
+fi
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_PATH_PROG(cat, cat)
diff --git a/docs/ChangeLog b/docs/ChangeLog
index aae30a25..ff7f8493 100644
--- a/docs/ChangeLog
+++ b/docs/ChangeLog
@@ -1,3 +1,68 @@
+Thu May 1 16:52:44 BST 2003 Colin Watson <cjwatson@debian.org>
+
+ Remove all assumptions that string literals have type 'char *'
+ rather than 'const char *'.
+
+ * configure.in (CFLAGS): Add -Wwrite-strings for gcc.
+
+ * lib/tempfile.c (xstrdup): First argument is const.
+ (path_search): Return 'const char *'.
+ (create_tempfile, create_tempdir): Copy return value of
+ path_search() right away rather than after checking for NULL.
+
+ * libdb/db_ver.c (dbver): Take a private copy of VER_KEY.
+ (dbver_wr): Take private copies of VER_KEY and VER_ID.
+
+ * src/accessdb.c (cat_root): Add const.
+ * src/catman.c (parse_for_sec): Remove __inline__; add const to both
+ arguments. Take private copies of "man" and the basic options.
+ (main): Copy "C" for locale. Make sections etc. 'const char **',
+ since STD_SECTIONS is an array of 'const char *'.
+ * src/check_mandirs.c (update_db_time, reset_db_time, update_db):
+ Take a private copy of KEY.
+ * src/filenames.c (make_filename): Make type const.
+ * src/filenames.h (make_filename): Update prototype.
+ * src/globbing.c (extension, mandir_layout): Add const.
+ * src/lexgrog.l (fname): Add const.
+ (find_name): Make filename const.
+ (main): Set program_name here from argv[0] rather than from a
+ string literal.
+ * include/manconfig.h.in (find_name): Update prototype.
+ * src/man.c (lang_dir): Add static. Copy string literals into ld.
+ Use xstrndup() rather than copying and then inserting '\0'.
+ (extension, alt_system_name, section_list, preprocessors, pager,
+ locale, std_sections, external, gxditview, html_pager): Add const.
+ (add_roff_line_length): First argument is const. Return a copy of
+ it if necessary.
+ (gripe_no_man): Copy external before passing it to basename().
+ (main): Copy "C" for internal_locale. Reorganize locale
+ reinitialization slightly so that locale can be const.
+ (man_getopt): Set 'const char *' and 'char *' variables to NULL
+ separately.
+ (is_section, compare_candidates, man): Use a 'const char **' to
+ iterate through section_list.
+ (make_roff_command): Remove __inline__. Take a copy of "" for dev
+ so that dev is always allocated memory. Handle filter in a more
+ const-safe way (although there's still a memory leak).
+ (get_section_list): Remove __inline__. Return 'const char **'.
+ * src/man.h (get_section_list): Update prototype.
+ * src/manp.c (get_from_list): Make return value and first argument
+ const.
+ (get_def): Make return value and both arguments const.
+ (get_sections): Return const.
+ (cat_manpath): Make path and catdir const.
+ * src/manp.h (get_def, get_sections): Update prototypes.
+ * src/manpath.c (main): Make alt_system const.
+ * src/whatis.c (use_grep): Make flags and anchor const.
+ (main): Make manp and alt_systems const. Copy "C" for locale.
+ * zsoelim/zsoelim.l (main): Copy argv[0] basename for program_name,
+ as basename()'s return value may not be long-lived. Copy "-" for
+ so_name[0].
+
+ * src/mandb.c (main): Don't bother remembering the return value of
+ setlocale().
+ * src/manpath.c (main): Likewise.
+
Mon Apr 28 15:11:28 BST 2003 Colin Watson <cjwatson@debian.org>
* src/catman.c (main): Don't guard xstrdup() from NULL input, as it
diff --git a/include/manconfig.h.in b/include/manconfig.h.in
index 62afd4ce..5a76b24b 100644
--- a/include/manconfig.h.in
+++ b/include/manconfig.h.in
@@ -306,7 +306,8 @@ extern int straycats (char *mandir);
/* lexgrog.l */
struct lexgrog;
-extern int find_name (const char *file, char *filename, struct lexgrog *p_lg);
+extern int find_name (const char *file, const char *filename,
+ struct lexgrog *p_lg);
/* util.c */
extern char *mkdbname (const char *path);
diff --git a/lib/tempfile.c b/lib/tempfile.c
index e73a931d..cdf4683a 100644
--- a/lib/tempfile.c
+++ b/lib/tempfile.c
@@ -37,13 +37,13 @@
/* Other library functions used in man-db. */
extern char *strappend (char *str, ...);
-extern char *xstrdup (char *string);
+extern char *xstrdup (const char *string);
extern int mkstemp (char *template);
extern char *mkdtemp (char *template);
-static char *path_search ()
+static const char *path_search ()
{
- char *dir = NULL;
+ const char *dir = NULL;
if (getuid () == geteuid () && getgid () == getegid ()) {
dir = getenv ("TMPDIR");
@@ -76,13 +76,12 @@ static char *path_search ()
*/
int create_tempfile (const char *template, char **created_filename)
{
- char *dir = path_search ();
+ char *dir = xstrdup (path_search ());
int fd;
mode_t old_mode;
if (!dir)
return -1;
- dir = xstrdup (dir);
*created_filename = strappend (dir, "/", template, "XXXXXX", NULL);
/* -rw------- */
old_mode = umask (S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
@@ -96,12 +95,11 @@ int create_tempfile (const char *template, char **created_filename)
*/
char *create_tempdir (const char *template)
{
- char *dir = path_search ();
+ char *dir = xstrdup (path_search ());
char *created_dirname;
if (!dir)
return NULL;
- dir = xstrdup (dir);
created_dirname = strappend (dir, "/", template, "XXXXXX", NULL);
mkdtemp (created_dirname);
return created_dirname;
diff --git a/libdb/db_ver.c b/libdb/db_ver.c
index 9f1c75e2..fe896145 100644
--- a/libdb/db_ver.c
+++ b/libdb/db_ver.c
@@ -49,33 +49,37 @@ static int dbver (MYDBM_FILE dbf)
{
datum key;
- key.dptr = VER_KEY;
+ key.dptr = xstrdup (VER_KEY);
key.dsize = sizeof VER_KEY;
content = MYDBM_FETCH (dbf, key);
+ free (key.dptr);
+
if (content.dptr == NULL)
return -1;
else if (!STREQ (content.dptr, VER_ID))
return 1;
else
return 0;
-
}
void dbver_wr (MYDBM_FILE dbf)
{
datum key, content;
- key.dptr = VER_KEY;
+ key.dptr = xstrdup (VER_KEY);
key.dsize = sizeof VER_KEY;
- content.dptr = VER_ID;
+ content.dptr = xstrdup (VER_ID);
content.dsize = sizeof VER_ID;
if (MYDBM_INSERT (dbf, key, content) != 0)
error (FATAL, 0,
_("fatal: unable to insert version identifier into %s"),
database);
+
+ free (key.dptr);
+ free (content.dptr);
}
int dbver_rd (MYDBM_FILE dbf)
diff --git a/src/accessdb.c b/src/accessdb.c
index 3ccaa56f..3123628d 100644
--- a/src/accessdb.c
+++ b/src/accessdb.c
@@ -59,7 +59,7 @@ extern char *strchr();
#endif /* HAVE_GETOPT_H */
char *program_name;
-char *cat_root;
+const char *cat_root;
int debug;
static const struct option long_options[] =
diff --git a/src/catman.c b/src/catman.c
index 0f7f8071..ffea8ea5 100644
--- a/src/catman.c
+++ b/src/catman.c
@@ -218,7 +218,7 @@ static void do_catman (char *argp[], int arg_no, int first_arg)
/* The last argument must be NULL */
argp[arg_no] = NULL;
-
+
catman (argp, arg_no);
/* don't free the last entry, it's NULL */
@@ -250,7 +250,7 @@ static __inline__ void reset_cursor (datum key)
/* find all pages that are in the supplied manpath and section and that are
ultimate source files. */
-static __inline__ int parse_for_sec (char *manpath, char *section)
+static int parse_for_sec (const char *manpath, const char *section)
{
char *argp[MAX_ARGS];
datum key;
@@ -260,23 +260,23 @@ static __inline__ int parse_for_sec (char *manpath, char *section)
if (rdopen_db () || dbver_rd (dbf))
return 1;
- argp[arg_no++] = "man"; /* Name of program */
+ argp[arg_no++] = xstrdup ("man"); /* Name of program */
#ifdef HAVE_SETLOCALE
/* As we supply a NULL environment to save precious execve() space,
we must also supply a locale if necessary */
if (locale) {
- argp[arg_no++] = "-L"; /* locale option */
- argp[arg_no++] = locale; /* The locale */
+ argp[arg_no++] = xstrdup ("-L"); /* locale option */
+ argp[arg_no++] = xstrdup (locale); /* The locale */
initial_bit += sizeof "-L" + strlen (locale) + 1;
} else
initial_bit = 0;
#endif /* HAVE_SETLOCALE */
- argp[arg_no++] = "-caM"; /* options */
- argp[arg_no++] = manpath; /* particular manpath */
- argp[arg_no++] = section; /* particular section */
+ argp[arg_no++] = xstrdup ("-caM"); /* options */
+ argp[arg_no++] = xstrdup (manpath); /* particular manpath */
+ argp[arg_no++] = xstrdup (section); /* particular section */
first_arg = arg_no; /* first pagename argument */
@@ -365,6 +365,10 @@ static __inline__ int parse_for_sec (char *manpath, char *section)
if (arg_no > first_arg)
do_catman (argp, arg_no, first_arg);
+ arg_no = first_arg - 1;
+ while (arg_no >= 0)
+ free (argp[arg_no--]);
+
return 0;
}
@@ -382,7 +386,8 @@ int main (int argc, char *argv[])
{
int c;
char *sys_manp;
- char **mp, **sections;
+ char **mp;
+ const char **sections;
int option_index; /* not used, but required by getopt_long() */
@@ -394,7 +399,7 @@ int main (int argc, char *argv[])
/* Obviously can't translate this. */
error (0, 0, "can't set the locale; make sure $LC_* and $LANG "
"are correct");
- locale = "C";
+ locale = xstrdup ("C");
}
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
@@ -428,10 +433,10 @@ int main (int argc, char *argv[])
/* If we were supplied sections: sort them out */
if (optind != argc) {
- char **sp;
+ const char **sp;
- sections = sp = (char **) xmalloc ((argc - optind + 1) *
- sizeof (char *));
+ sections = sp = xmalloc ((argc - optind + 1) *
+ sizeof *sections);
while (optind != argc)
*sp++ = argv[optind++];
*sp = NULL;
@@ -441,28 +446,29 @@ int main (int argc, char *argv[])
mansect = getenv ("MANSECT");
if (mansect && *mansect) {
/* MANSECT contains sections */
- char *sec;
+ const char *sec;
int i = 0;
mansect = xstrdup (mansect);
sections = NULL;
for (sec = strtok (mansect, ":"); sec;
sec = strtok (NULL, ":")) {
- sections = (char **) xrealloc (sections,
- (i + 2) *
- sizeof (char *));
+ sections = xrealloc (sections,
+ (i + 2) *
+ sizeof *sections);
sections[i++] = sec;
}
sections[i] = NULL;
+ free (mansect);
} else {
/* use default sections */
- static char *std_sections[] = STD_SECTIONS;
+ static const char *std_sections[] = STD_SECTIONS;
sections = std_sections;
}
}
if (debug) {
- char **sp;
+ const char **sp;
for (sp = sections; *sp; sp++)
fprintf (stderr, "sections: %s\n", *sp);
@@ -487,7 +493,8 @@ int main (int argc, char *argv[])
create_pathlist (manp, manpathlist);
for (mp = manpathlist; *mp; mp++) {
- char *catpath, **sp;
+ char *catpath;
+ const char **sp;
size_t len;
catpath = get_catpath (*mp, SYSTEM_CAT | USER_CAT);
diff --git a/src/check_mandirs.c b/src/check_mandirs.c
index b2f2e1ff..e4259e20 100644
--- a/src/check_mandirs.c
+++ b/src/check_mandirs.c
@@ -429,7 +429,7 @@ void update_db_time (void)
datum key1, content1;
#endif /* FAST_BTREE */
- key.dptr = KEY;
+ key.dptr = xstrdup (KEY);
key.dsize = sizeof KEY;
content.dptr = (char *) xmalloc (16); /* 11 is max long with '\0' */
(void) sprintf (content.dptr, "%ld", (long) time (NULL));
@@ -462,6 +462,7 @@ void update_db_time (void)
#endif /* !FAST_BTREE */
MYDBM_CLOSE (dbf);
+ free (key.dptr);
free (content.dptr);
}
@@ -471,7 +472,7 @@ void reset_db_time (void)
{
datum key;
- key.dptr = KEY;
+ key.dptr = xstrdup (KEY);
key.dsize = sizeof KEY;
/* we don't really care if we can't open it RW - it's not fatal */
@@ -488,6 +489,7 @@ void reset_db_time (void)
if (debug)
fprintf (stderr, "reset_db_time()\n");
MYDBM_CLOSE (dbf);
+ free (key.dptr);
}
/* routine to prepare/create the db prior to calling testmandirs() */
@@ -540,10 +542,11 @@ short update_db (const char *manpath)
datum key, content;
short new;
- key.dptr = KEY;
+ key.dptr = xstrdup (KEY);
key.dsize = sizeof KEY;
content = MYDBM_FETCH (dbf, key);
MYDBM_CLOSE (dbf);
+ free (key.dptr);
if (debug)
fprintf (stderr, "update_db(): %ld\n",
diff --git a/src/filenames.c b/src/filenames.c
index 1235385e..6844c43b 100644
--- a/src/filenames.c
+++ b/src/filenames.c
@@ -54,7 +54,7 @@ static void gripe_bogus_manpage (const char *manpage)
}
char *make_filename (const char *path, const char *name,
- struct mandata *in, char *type)
+ struct mandata *in, const char *type)
{
static char *file;
diff --git a/src/filenames.h b/src/filenames.h
index 26bac7b3..7192ce57 100644
--- a/src/filenames.h
+++ b/src/filenames.h
@@ -23,6 +23,6 @@
#include "libdb/db_storage.h"
extern char *make_filename (const char *path, const char *name,
- struct mandata *in, char *type);
+ struct mandata *in, const char *type);
extern char *filename_info (const char *file, struct mandata *info,
const char *req_name);
diff --git a/src/globbing.c b/src/globbing.c
index 398e10c6..fb1cc61f 100644
--- a/src/globbing.c
+++ b/src/globbing.c
@@ -64,8 +64,8 @@ extern char *strrchr();
#include "lib/error.h"
#include "lib/hashtable.h"
-char *extension;
-static char *mandir_layout = MANDIR_LAYOUT;
+const char *extension;
+static const char *mandir_layout = MANDIR_LAYOUT;
#ifdef TEST
diff --git a/src/lexgrog.l b/src/lexgrog.l
index 7a39a3b8..fb84e6ab 100644
--- a/src/lexgrog.l
+++ b/src/lexgrog.l
@@ -73,7 +73,8 @@ static void add_separator_to_whatis (void);
static void newline_found (void);
static char newname[MAX_NAME];
-static char *p_name, *fname;
+static char *p_name;
+static const char *fname;
static char filters[MAX_FILTERS];
static int fill_mode;
@@ -87,7 +88,7 @@ static int fill_mode;
# include "lib/getopt.h"
#endif /* HAVE_GETOPT_H */
-char *program_name = "lexgrog";
+char *program_name;
int debug = 0;
static const struct option long_options[] =
@@ -367,7 +368,7 @@ static void newline_found (void)
}
}
-int find_name (const char *file, char *filename, lexgrog *p_lg)
+int find_name (const char *file, const char *filename, lexgrog *p_lg)
{
int ret;
@@ -468,6 +469,9 @@ int main (int argc, char **argv)
int type = 0;
int parse_man = 0, parse_cat = 0, show_whatis = 0, show_filters = 0;
int some_failed = 0;
+
+ program_name = xstrdup (basename (argv[0]));
+
while ((c = getopt_long (argc, argv, args,
long_options, &option_index)) != -1) {
switch (c) {
diff --git a/src/man.c b/src/man.c
index 4e534b2d..b90a4f7b 100644
--- a/src/man.c
+++ b/src/man.c
@@ -230,13 +230,13 @@ static FILE *checked_popen (const char *command, const char *type)
}
#endif /* MAN_CATS */
-char *lang_dir (const char *filename)
+static char *lang_dir (const char *filename)
{
char *ld; /* the lang dir: point to static data */
const char *fm; /* the first "/man/" dir */
const char *sm; /* the second "/man?/" dir */
- ld = "";
+ ld = xstrdup ("");
if (!filename)
return ld;
@@ -254,15 +254,15 @@ char *lang_dir (const char *filename)
/* If there's no lang dir element, it's an English man page. */
if (sm == fm + 4)
- return "C";
+ return xstrdup ("C");
/* found a lang dir */
fm += 5;
sm = strchr (fm, '/');
if (!sm)
return ld;
- ld = xstrdup (fm);
- ld[sm - fm] = '\0';
+ free (ld);
+ ld = xstrndup (fm, sm - fm);
if (debug)
fprintf (stderr, "found lang dir element %s\n", ld);
return ld;
@@ -295,23 +295,23 @@ int quiet = 1;
char *program_name;
char *database;
MYDBM_FILE dbf;
-extern char *extension; /* for globbing.c */
+extern const char *extension; /* for globbing.c */
extern char *user_config_file; /* defined in manp.c */
/* locals */
-static char *alt_system_name;
-static char **section_list;
+static const char *alt_system_name;
+static const char **section_list;
static const char *section;
static char *colon_sep_section_list;
-static char *preprocessors;
-static char *pager;
-static char *locale;
+static const char *preprocessors;
+static const char *pager;
+static const char *locale;
static char *internal_locale;
static char *prompt_string;
static char *less;
-static char *std_sections[] = STD_SECTIONS;
+static const char *std_sections[] = STD_SECTIONS;
static char *manp;
-static char *external;
+static const char *external;
static struct hashtable *db_hash = NULL;
static int troff;
@@ -381,9 +381,9 @@ static const char args[] = "7DlM:P:S:adfhH::kVum:p:tT::wWe:L:Zcr:X::E:iIC:";
# ifdef TROFF_IS_GROFF
static int ditroff;
-static char *gxditview;
+static const char *gxditview;
static int htmlout;
-static char *html_pager;
+static const char *html_pager;
# endif /* TROFF_IS_GROFF */
#else /* !HAS_TROFF */
@@ -565,7 +565,7 @@ static int get_roff_line_length (void)
return 0;
}
-static char *add_roff_line_length (char *filter, int *save_cat)
+static char *add_roff_line_length (const char *filter, int *save_cat)
{
int length = get_roff_line_length ();
if (length) {
@@ -576,7 +576,7 @@ static char *add_roff_line_length (char *filter, int *save_cat)
sprintf (options, " -rLL=%dn -rLT=%dn", length, length);
return strappend (NULL, filter, options, NULL);
}
- return filter;
+ return xstrdup (filter);
}
#ifdef UNDOC_COMMAND
@@ -654,7 +654,8 @@ static __inline__ void gripe_no_man (const char *name, const char *sec)
static void do_extern (char *argv[])
{
/* privs are already dropped */
- argv[0] = basename (external);
+ char *external_copy = xstrdup (external);
+ argv[0] = basename (external_copy);
execv (external, argv);
exit (FATAL);
}
@@ -888,10 +889,7 @@ int main (int argc, char *argv[])
if (multiple_locale)
internal_locale = multiple_locale;
}
- if (internal_locale != NULL)
- internal_locale = xstrdup (internal_locale);
- else
- internal_locale = "C";
+ internal_locale = xstrdup (internal_locale ? internal_locale : "C");
/* export argv, it might be needed when invoking the vendor supplied browser */
#if defined _AIX || defined __sgi
@@ -952,11 +950,11 @@ int main (int argc, char *argv[])
/* close this locale and reinitialise if a new locale was
issued as an argument or in $MANOPT */
if (locale) {
- internal_locale = setlocale (LC_ALL, locale);
+ free (internal_locale);
+ internal_locale = xstrdup (setlocale (LC_ALL, locale));
if (internal_locale == NULL)
- internal_locale = locale;
+ internal_locale = xstrdup (locale);
- internal_locale = xstrdup (internal_locale);
if (debug)
fprintf(stderr,
"main(): locale = %s, internal_locale = %s\n",
@@ -1274,7 +1272,7 @@ static void man_getopt (int argc, char *argv[])
break;
case 'H':
#ifdef TROFF_IS_GROFF
- html_pager = (optarg ? optarg : 0);
+ html_pager = (optarg ? optarg : NULL);
htmlout = 1;
troff = 1;
roff_device = "html";
@@ -1313,9 +1311,9 @@ static void man_getopt (int argc, char *argv[])
html_pager = NULL;
#endif
roff_device = extension = pager = locale
- = colon_sep_section_list
= alt_system_name = external
- = preprocessors = manp = NULL;
+ = preprocessors = NULL;
+ colon_sep_section_list = manp = NULL;
break;
case 'h':
usage(OK);
@@ -1351,7 +1349,7 @@ static void man_getopt (int argc, char *argv[])
*/
static __inline__ const char *is_section (const char *name)
{
- char **vs;
+ const char **vs;
for (vs = section_list; *vs; vs++) {
if (STREQ (*vs, name))
@@ -1469,8 +1467,8 @@ static __inline__ void create_stdintmp (void)
}
/* Return command (malloced string) to format file to stdout */
-static __inline__ char *make_roff_command (const char *dir, const char *file,
- const char *dbfilters)
+static char *make_roff_command (const char *dir, const char *file,
+ const char *dbfilters)
{
const char *pp_string;
char *fmt_prog;
@@ -1681,10 +1679,10 @@ static __inline__ char *make_roff_command (const char *dir, const char *file,
else if (roff_device)
dev = strappend (NULL, " -T", roff_device, NULL);
else
- dev = "";
+ dev = xstrdup ("");
do {
- char *filter;
+ const char *filter = NULL;
int wants_dev = 0; /* filter wants a dev argument */
/* set filter according to *pp_string, on
@@ -1715,6 +1713,7 @@ static __inline__ char *make_roff_command (const char *dir, const char *file,
/* done with preprocessors, now add roff */
#ifdef TROFF_IS_GROFF
if (troff && ditroff)
+ /* TODO: leak */
filter = strappend (NULL,
get_def ("troff",
TROFF),
@@ -1726,6 +1725,7 @@ static __inline__ char *make_roff_command (const char *dir, const char *file,
else {
filter = get_def ("nroff", NROFF);
#ifdef TROFF_IS_GROFF
+ /* TODO: leak */
filter = add_roff_line_length
(filter, &save_cat);
#endif
@@ -1733,11 +1733,9 @@ static __inline__ char *make_roff_command (const char *dir, const char *file,
wants_dev = 1;
break;
- default:
- filter = "";
}
- if (*filter) {
+ if (filter && *filter) {
command = strappend (command,
" | ",
filter,
@@ -1757,8 +1755,7 @@ static __inline__ char *make_roff_command (const char *dir, const char *file,
command = strappend (command, " | ", COL, NULL);
#endif /* GNU_NROFF */
- if (roff_device || gxditview)
- free (dev);
+ free (dev);
} else {
/* use external formatter script, it takes arguments
input file, preprocessor string, and (optional)
@@ -2652,7 +2649,6 @@ static int compare_candidates (const struct mandata *left,
const struct mandata *right,
const char *req_name)
{
- char **sp;
int sec_left = 0, sec_right = 0, cmp;
/* If one candidate matches the requested name exactly, sort it
@@ -2672,6 +2668,7 @@ static int compare_candidates (const struct mandata *left,
/* Find out whether left->ext is ahead of right->ext in
* section_list.
*/
+ const char **sp;
for (sp = section_list; *sp; sp++) {
if (!*(*sp + 1)) {
/* No extension */
@@ -3342,7 +3339,7 @@ static int man (const char *name, int *found)
for (mp = manpathlist; *mp; mp++)
*found += locate_page (*mp, section, name, &candidates);
} else {
- char **sp;
+ const char **sp;
for (sp = section_list; *sp; sp++) {
char **mp;
@@ -3360,12 +3357,12 @@ static int man (const char *name, int *found)
}
-static __inline__ char **get_section_list (void)
+static const char **get_section_list (void)
{
int i = 0;
- char **config_sections;
- char **sections = NULL;
- char *sec;
+ const char **config_sections;
+ const char **sections = NULL;
+ const char *sec;
/* Section list from configuration file, or STD_SECTIONS if it's
* empty.
@@ -3381,8 +3378,7 @@ static __inline__ char **get_section_list (void)
for (sec = strtok (colon_sep_section_list, ":"); sec;
sec = strtok (NULL, ":")) {
- sections = (char **) xrealloc (sections,
- (i + 2) * sizeof (char *));
+ sections = xrealloc (sections, (i + 2) * sizeof *sections);
sections[i++] = sec;
}
diff --git a/src/man.h b/src/man.h
index 5d1fdfae..9c7ff620 100644
--- a/src/man.h
+++ b/src/man.h
@@ -25,7 +25,7 @@
/* man.c */
static void man_getopt (int argc, char *argv[]);
static __inline__ const char *is_section (const char *name);
-static __inline__ char **get_section_list (void);
+static const char **get_section_list (void);
static int man (const char *name, int *found);
static int display (const char *dir, const char *man_file,
const char *cat_file, const char *title,
diff --git a/src/mandb.c b/src/mandb.c
index 4ef181c1..d92b7c35 100644
--- a/src/mandb.c
+++ b/src/mandb.c
@@ -420,7 +420,6 @@ int main (int argc, char *argv[])
int purged = 0;
int quiet_temp = 0;
char **mp;
- char *locale;
int option_index; /* not used, but required by getopt_long() */
@@ -436,13 +435,10 @@ int main (int argc, char *argv[])
program_name = xstrdup (basename (argv[0]));
/* initialise the locale */
- locale = xstrdup (setlocale (LC_ALL, ""));
- if (!locale) {
+ if (!setlocale (LC_ALL, ""))
/* Obviously can't translate this. */
error (0, 0, "can't set the locale; make sure $LC_* and $LANG "
"are correct");
- locale = "C";
- }
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
diff --git a/src/manp.c b/src/manp.c
index db0aaf1d..d6e37ebe 100644
--- a/src/manp.c
+++ b/src/manp.c
@@ -144,7 +144,7 @@ static void add_to_list (const char *key, const char *cont, int flag)
namestore = list;
}
-static char *get_from_list (char *key, int flag)
+static const char *get_from_list (const char *key, int flag)
{
struct list *list;
@@ -166,9 +166,9 @@ static struct list *iterate_over_list (struct list *prev, char *key, int flag)
return NULL;
}
-char *get_def (char *thing, char *def)
+const char *get_def (const char *thing, const char *def)
{
- char *config_def = get_from_list (thing, DEFINE);
+ const char *config_def = get_from_list (thing, DEFINE);
return config_def ? config_def : def;
}
@@ -197,11 +197,11 @@ static void add_sections (char *sections)
}
}
-char **get_sections (void)
+const char **get_sections (void)
{
struct list *list;
int length = 0;
- char **sections, **sectionp;
+ const char **sections, **sectionp;
for (list = namestore; list; list = list->next)
if (list->flag == SECTION)
@@ -354,7 +354,8 @@ static __inline__ void gripe_not_directory (const char *dir)
catpath list */
char *cat_manpath (char *manp)
{
- char *catp = NULL, *path, *catdir;
+ char *catp = NULL;
+ const char *path, *catdir;
for (path = strsep (&manp, ":"); path; path = strsep (&manp, ":")) {
catdir = get_from_list (path, MANDB_MAP_USER);
diff --git a/src/manp.h b/src/manp.h
index 8b9ee0a2..279915dd 100644
--- a/src/manp.h
+++ b/src/manp.h
@@ -31,5 +31,5 @@ extern char *get_mandb_manpath (void);
extern char *get_catpath (const char *name, int cattype);
extern int is_global_mandir (const char *dir);
extern void read_config_file (void);
-extern char *get_def (char *thing, char *def);
-extern char **get_sections (void);
+extern const char *get_def (const char *thing, const char *def);
+extern const char **get_sections (void);
diff --git a/src/manpath.c b/src/manpath.c
index 32bb9211..cba81bfc 100644
--- a/src/manpath.c
+++ b/src/manpath.c
@@ -113,22 +113,16 @@ static void usage (int status)
int main (int argc, char *argv[])
{
int c, global = 0, cat = 0;
- char *alt_system = "";
+ const char *alt_system = "";
char *path_string;
int option_index; /* not used, but required by getopt_long() */
- char *locale;
program_name = xstrdup (basename (argv[0]));
/* initialise the locale */
- locale = setlocale (LC_ALL, "");
- if (locale)
- locale = xstrdup (locale);
- else {
+ if (!setlocale (LC_ALL, ""))
/* Obviously can't translate this. */
error (0, 0, "can't set the locale; make sure $LC_* and $LANG "
"are correct");
- locale = "C";
- }
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
diff --git a/src/whatis.c b/src/whatis.c
index 4ddec94e..c9d05f54 100644
--- a/src/whatis.c
+++ b/src/whatis.c
@@ -183,7 +183,8 @@ static __inline__ int use_grep (char *page, char *manpath)
if (access (whatis_file, R_OK) == 0) {
char *esc_page = escape_shell (page);
char *esc_file = escape_shell (whatis_file);
- char *flags, *anchor, *command;
+ const char *flags, *anchor;
+ char *command;
#if defined(WHATIS)
flags = get_def ("whatis_grep_flags", WHATIS_GREP_FLAGS);
anchor = "^";
@@ -599,8 +600,8 @@ static void search (char *page)
int main (int argc, char *argv[])
{
int c;
- char *manp = NULL, *alt_systems = "";
- char *llocale = 0, *locale;
+ const char *manp = NULL, *alt_systems = "";
+ char *llocale = NULL, *locale;
int option_index;
program_name = xstrdup (basename (argv[0]));
@@ -611,7 +612,7 @@ int main (int argc, char *argv[])
/* Obviously can't translate this. */
error (0, 0, "can't set the locale; make sure $LC_* and $LANG "
"are correct");
- locale = "C";
+ locale = xstrdup ("C");
}
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
@@ -674,6 +675,7 @@ int main (int argc, char *argv[])
issued as an argument or in $MANOPT */
if (llocale) {
setlocale (LC_ALL, llocale);
+ free (locale);
locale = xstrdup (llocale);
if (debug)
fprintf(stderr,
diff --git a/zsoelim/zsoelim.l b/zsoelim/zsoelim.l
index 10521d97..76ff9e43 100644
--- a/zsoelim/zsoelim.l
+++ b/zsoelim/zsoelim.l
@@ -337,7 +337,7 @@ int main(int argc, char *argv[])
{
int c, option_index;
- program_name = basename(argv[0]);
+ program_name = xstrdup(basename(argv[0]));
while ( (c = getopt_long(argc, argv, args,
long_options, &option_index)) != EOF ) {
@@ -359,7 +359,7 @@ int main(int argc, char *argv[])
/* if we have any arguments, parse them in command line order, else
open stdin */
if (optind == argc) {
- so_name[0] = "-";
+ so_name[0] = xstrdup("-");
parse_file();
} else {
while (optind < argc) {