Hi Karl,

I just built texinfo-4.3 (on ix86-linux-gnu with gcc-2.95.3) and saw
that there are a lots of gcc warnings. They all concern the use of constant
strings, i.e. `const char *' in assignments to non-constant `char *'
variables, as initializer for such variables, or as arguments of that type.

I think these warnings are all legitimate and point to the potential problem
that the constant strings could be modified by the program.

Therefore, I would like to suggest the attached patch. Except in one case
(in makeinfo/index.c index_node was used first for a constant a then for a
modifiable string) the patch just adds a bunch of `const's to existing
declarations. From the fact that the patch removes all gcc warnings, I
deduce that the above mentioned problem doesn't actually occur in the
texinfo-4.3 code (as far as the compiler can detect, since the majority of
functions is used without suitable prototypes).

NB: Does texinfo (and other GNU software) actually still support
prototype-unaware compilers. If not, it might be a good idea to supply all
necessary prototypes. Or even better supply them in any case with the
        TYPE name _P((ARG TYES));
syntax. I know that doing this is rather tedious, but a lot of subtle bugs
have been found this way (in other programs).

regards
Peter Breitenlohner <[EMAIL PROTECTED]>
diff -ur texinfo-4.3.orig/info/indices.c texinfo-4.3/info/indices.c
--- texinfo-4.3.orig/info/indices.c     2002-08-26 01:38:38.000000000 +0200
+++ texinfo-4.3/info/indices.c  2002-11-15 21:23:31.000000000 +0100
@@ -390,7 +390,7 @@
   /* Report to the user on what we have found. */
   {
     register int j;
-    char *name = _("CAN'T SEE THIS");
+    const char *name = _("CAN'T SEE THIS");
     char *match;
 
     for (j = 0; index_nodenames[j]; j++)
diff -ur texinfo-4.3.orig/info/info.c texinfo-4.3/info/info.c
--- texinfo-4.3.orig/info/info.c        2002-08-26 01:38:38.000000000 +0200
+++ texinfo-4.3/info/info.c     2002-11-15 21:24:27.000000000 +0100
@@ -609,22 +609,22 @@
    use them that way.  This also has the advantage that there's only one
    copy of the strings.  */
 
-char *msg_cant_find_node;
-char *msg_cant_file_node;
-char *msg_cant_find_window;
-char *msg_cant_find_point;
-char *msg_cant_kill_last;
-char *msg_no_menu_node;
-char *msg_no_foot_node;
-char *msg_no_xref_node;
-char *msg_no_pointer;
-char *msg_unknown_command;
-char *msg_term_too_dumb;
-char *msg_at_node_bottom;
-char *msg_at_node_top;
-char *msg_one_window;
-char *msg_win_too_small;
-char *msg_cant_make_help;
+const char *msg_cant_find_node;
+const char *msg_cant_file_node;
+const char *msg_cant_find_window;
+const char *msg_cant_find_point;
+const char *msg_cant_kill_last;
+const char *msg_no_menu_node;
+const char *msg_no_foot_node;
+const char *msg_no_xref_node;
+const char *msg_no_pointer;
+const char *msg_unknown_command;
+const char *msg_term_too_dumb;
+const char *msg_at_node_bottom;
+const char *msg_at_node_top;
+const char *msg_one_window;
+const char *msg_win_too_small;
+const char *msg_cant_make_help;
 
 static void
 init_messages ()
diff -ur texinfo-4.3.orig/info/info.h texinfo-4.3/info/info.h
--- texinfo-4.3.orig/info/info.h        2002-08-26 01:38:38.000000000 +0200
+++ texinfo-4.3/info/info.h     2002-11-15 21:42:51.000000000 +0100
@@ -128,22 +128,22 @@
 extern void info_error ();
 
 /* Error message defines. */
-extern char *msg_cant_find_node;
-extern char *msg_cant_file_node;
-extern char *msg_cant_find_window;
-extern char *msg_cant_find_point;
-extern char *msg_cant_kill_last;
-extern char *msg_no_menu_node;
-extern char *msg_no_foot_node;
-extern char *msg_no_xref_node;
-extern char *msg_no_pointer;
-extern char *msg_unknown_command;
-extern char *msg_term_too_dumb;
-extern char *msg_at_node_bottom;
-extern char *msg_at_node_top;
-extern char *msg_one_window;
-extern char *msg_win_too_small;
-extern char *msg_cant_make_help;
+extern const char *msg_cant_find_node;
+extern const char *msg_cant_file_node;
+extern const char *msg_cant_find_window;
+extern const char *msg_cant_find_point;
+extern const char *msg_cant_kill_last;
+extern const char *msg_no_menu_node;
+extern const char *msg_no_foot_node;
+extern const char *msg_no_xref_node;
+extern const char *msg_no_pointer;
+extern const char *msg_unknown_command;
+extern const char *msg_term_too_dumb;
+extern const char *msg_at_node_bottom;
+extern const char *msg_at_node_top;
+extern const char *msg_one_window;
+extern const char *msg_win_too_small;
+extern const char *msg_cant_make_help;
 
 
 extern char *filename_non_directory ();        /* Found in info-utils.c. */
diff -ur texinfo-4.3.orig/info/nodemenu.c texinfo-4.3/info/nodemenu.c
--- texinfo-4.3.orig/info/nodemenu.c    2002-08-26 01:38:38.000000000 +0200
+++ texinfo-4.3/info/nodemenu.c 2002-11-15 21:20:28.000000000 +0100
@@ -22,7 +22,7 @@
 #include "info.h"
 
 /* Return a line describing the format of a node information line. */
-static char *
+static const char *
 nodemenu_format_info ()
 {
   return (_("\n\
diff -ur texinfo-4.3.orig/info/session.c texinfo-4.3/info/session.c
--- texinfo-4.3.orig/info/session.c     2002-08-26 01:38:38.000000000 +0200
+++ texinfo-4.3/info/session.c  2002-11-15 21:28:43.000000000 +0100
@@ -2433,7 +2433,8 @@
 info_follow_menus (initial_node, menus, errstr, errarg1, errarg2)
      NODE *initial_node;
      char **menus;
-     char **errstr, **errarg1, **errarg2;
+     const char **errstr;
+     char **errarg1, **errarg2;
 {
   NODE *node = NULL;
   *errstr = *errarg1 = *errarg2 = NULL;
@@ -2796,7 +2797,7 @@
 DECLARE_INFO_COMMAND (info_goto_invocation_node,
                      _("Find the node describing program invocation"))
 {
-  char *invocation_prompt = _("Find Invocation node of [%s]: ");
+  const char *invocation_prompt = _("Find Invocation node of [%s]: ");
   char *program_name, *line;
   char *default_program_name, *prompt, *file_name;
   NODE *top_node;
@@ -3848,7 +3849,8 @@
      int failing_p;
 {
   register int i;
-  char *prefix, *prompt, *p_rep;
+  const char *prefix;
+  char *prompt, *p_rep;
   int prompt_len, p_rep_index, p_rep_size;
 
   if (dir < 0)
diff -ur texinfo-4.3.orig/info/window.c texinfo-4.3/info/window.c
--- texinfo-4.3.orig/info/window.c      2002-08-26 01:38:38.000000000 +0200
+++ texinfo-4.3/info/window.c   2002-11-15 21:29:48.000000000 +0100
@@ -1144,7 +1144,7 @@
     int modeline_len = 0;
     char *parent = NULL, *filename = "*no file*";
     char *nodename = "*no node*";
-    char *update_message = NULL;
+    const char *update_message = NULL;
     NODE *node = window->node;
 
     if (node)
diff -ur texinfo-4.3.orig/makeinfo/defun.c texinfo-4.3/makeinfo/defun.c
--- texinfo-4.3.orig/makeinfo/defun.c   2002-11-11 09:01:55.000000000 +0100
+++ texinfo-4.3/makeinfo/defun.c        2002-11-15 21:32:02.000000000 +0100
@@ -331,7 +331,8 @@
 {
   enum insertion_type base_type;
   char **defun_args, **scan_args;
-  char *category, *defined_name, *type_name, *type_name2;
+  const char *category;
+  char *defined_name, *type_name, *type_name2;
 
   {
     char *line;
diff -ur texinfo-4.3.orig/makeinfo/html.c texinfo-4.3/makeinfo/html.c
--- texinfo-4.3.orig/makeinfo/html.c    2002-11-04 23:14:40.000000000 +0100
+++ texinfo-4.3/makeinfo/html.c 2002-11-15 21:32:54.000000000 +0100
@@ -33,7 +33,7 @@
 void
 html_output_head ()
 {
-  static char *html_title = NULL;
+  static const char *html_title = NULL;
 
   if (html_output_head_p)
     return;
diff -ur texinfo-4.3.orig/makeinfo/index.c texinfo-4.3/makeinfo/index.c
--- texinfo-4.3.orig/makeinfo/index.c   2002-11-07 23:16:20.000000000 +0100
+++ texinfo-4.3/makeinfo/index.c        2002-11-15 22:11:19.000000000 +0100
@@ -696,7 +696,7 @@
         {
           /* A pathological document might have an index entry outside of any
              node.  Don't crash; try using the section name instead.  */
-          char *index_node = index->node;
+          const char *index_node = index->node;
           
           line_number = index->defining_line;
           input_filename = index->defining_file;
@@ -741,12 +741,14 @@
               if (index->node && *index->node)
                 {
                   /* Make sure any non-macros in the node name are expanded.  */
+                  char *expanded_index;
+                  
                   in_fixed_width_font++;
-                  index_node = expansion (index_node, 0);
+                  expanded_index = expansion (index_node, 0);
                   in_fixed_width_font--;
-                  add_anchor_name (index_node, 1);
-                  add_word_args ("\">%s</a>", index_node);
-                  free (index_node);
+                  add_anchor_name (expanded_index, 1);
+                  add_word_args ("\">%s</a>", expanded_index);
+                  free (expanded_index);
                 }
               else if (STREQ (index_node, _("(outside of any node)")))
                 {
diff -ur texinfo-4.3.orig/makeinfo/insertion.c texinfo-4.3/makeinfo/insertion.c
--- texinfo-4.3.orig/makeinfo/insertion.c       2002-11-12 09:08:06.000000000 +0100
+++ texinfo-4.3/makeinfo/insertion.c    2002-11-15 22:13:09.000000000 +0100
@@ -190,7 +190,7 @@
 
  /* Return a pointer to the print name of this
     enumerated type. */
-char *
+const char *
 insertion_type_pname (type)
      enum insertion_type type;
 {
@@ -979,7 +979,7 @@
         break;
       else
         {
-          char *offender = insertion_type_pname (insertion_stack->insertion);
+          const char *offender = insertion_type_pname (insertion_stack->insertion);
 
           file_line_error (insertion_stack->filename,
                            insertion_stack->line_number,
diff -ur texinfo-4.3.orig/makeinfo/makeinfo.c texinfo-4.3/makeinfo/makeinfo.c
--- texinfo-4.3.orig/makeinfo/makeinfo.c        2002-11-13 01:34:10.000000000 +0100
+++ texinfo-4.3/makeinfo/makeinfo.c     2002-11-15 21:59:45.000000000 +0100
@@ -193,7 +193,7 @@
 
 #if defined (VA_FPRINTF) && __STDC__
 /* Unfortunately we must use prototypes if we are to use <stdarg.h>.  */
-void add_word_args (char *, ...);
+void add_word_args (const char *, ...);
 void execute_string (char *, ...);
 #else
 void add_word_args ();
@@ -218,10 +218,10 @@
 /* Print an error message, and return false. */
 void
 #if defined (VA_FPRINTF) && __STDC__
-error (char *format, ...)
+error (const char *format, ...)
 #else
 error (format, va_alist)
-     char *format;
+     const char *format;
      va_dcl
 #endif
 {
@@ -245,12 +245,12 @@
 /* Just like error (), but print the input file and line number as well. */
 void
 #if defined (VA_FPRINTF) && __STDC__
-file_line_error (char *infile, int lno, char *format, ...)
+file_line_error (char *infile, int lno, const char *format, ...)
 #else
 file_line_error (infile, lno, format, va_alist)
    char *infile;
    int lno;
-   char *format;
+   const char *format;
    va_dcl
 #endif
 {
@@ -276,10 +276,10 @@
    number from global variables. */
 void
 #if defined (VA_FPRINTF) && __STDC__
-line_error (char *format, ...)
+line_error (const char *format, ...)
 #else
 line_error (format, va_alist)
-   char *format;
+   const char *format;
    va_dcl
 #endif
 {
@@ -303,10 +303,10 @@
 
 void
 #if defined (VA_FPRINTF) && __STDC__
-warning (char *format, ...)
+warning (const char *format, ...)
 #else
 warning (format, va_alist)
-     char *format;
+     const char *format;
      va_dcl
 #endif
 {
@@ -1362,7 +1362,7 @@
       strcat (output_filename, basename);
       if (mkdir (output_filename, 0777) == -1)
         {
-          char *errmsg = strerror (errno);
+          const char *errmsg = strerror (errno);
 
           if ((errno == EEXIST
 #ifdef __MSDOS__
@@ -2146,7 +2146,7 @@
 /* Return the string which invokes PROC; a pointer to a function.
    Always returns the first function in the command table if more than
    one matches PROC.  */
-static char *
+static const char *
 find_proc_name (proc)
      COMMAND_FUNCTION *proc;
 {
@@ -2172,7 +2172,7 @@
     {
       if (brace_stack->proc != misplaced_brace)
         {
-          char *proc_name;
+          const char *proc_name;
 
           proc_name = find_proc_name (brace_stack->proc);
           file_line_error (input_filename, brace_stack->line,
@@ -2226,10 +2226,10 @@
 
 void
 #if defined (VA_FPRINTF) && __STDC__
-add_word_args (char *format, ...)
+add_word_args (const char *format, ...)
 #else
 add_word_args (format, va_alist)
-    char *format;
+    const char *format;
     va_dcl
 #endif
 {
diff -ur texinfo-4.3.orig/makeinfo/makeinfo.h texinfo-4.3/makeinfo/makeinfo.h
--- texinfo-4.3.orig/makeinfo/makeinfo.h        2002-09-29 21:15:20.000000000 +0200
+++ texinfo-4.3/makeinfo/makeinfo.h     2002-11-15 22:17:06.000000000 +0100
@@ -153,7 +153,7 @@
 DECLARE (char *, copying_text, NULL);
 
 /* @documentdescription ... @end documentdescription. */
-DECLARE (char *, document_description, NULL);
+DECLARE (const char *, document_description, NULL);
 
 /* Nonzero if the last character inserted has the syntax class of NEWLINE. */
 DECLARE (int, last_char_was_newline, 1);
diff -ur texinfo-4.3.orig/makeinfo/node.c texinfo-4.3/makeinfo/node.c
--- texinfo-4.3.orig/makeinfo/node.c    2002-11-05 04:04:26.000000000 +0100
+++ texinfo-4.3/makeinfo/node.c 2002-11-15 21:36:18.000000000 +0100
@@ -1291,7 +1291,7 @@
 /* The strings here are followed in the message by `reference to...' in
    the `validate' routine.  They are only used in messages, thus are
    translated.  */
-static char *
+static const char *
 reftype_type_string (type)
      enum reftype type;
 {

Reply via email to