branch-1_4 warning cleanup

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.m4.patches
Message-ID <[email protected]>
Found a couple of problems on both the branch and head using some compiler 
flags.  There are several places where we assign "" to a char*, so when I port 
this to head, I hope to fix things in head by adding const rather than the 
quicker hack used here.  However, I did verify that in those places, we never 
try to alter the contents of "", so fortunately we don't trigger a segfault for 
trying to modify a read-only string.

2006-10-26  Eric Blake  <[email protected]>

	Silence -Wwrite-strings -Wpointer-arith warnings.
	* src/builtin.c (define_user_macro): Allow NULL argument.
	(m4_builtin, m4_indir): Cast away const of "".
	* src/format.c (format): Likewise.
	* src/macro.c (collect_arguments): Likewise.
	(expand_macro): Avoid math on void*.
	* src/m4.c (main): Adjust caller.
	* src/output.c (freeze_diversions): Detect off_t overflow.

Index: src/builtin.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/builtin.c,v
retrieving revision 1.1.1.1.2.45
diff -u -r1.1.1.1.2.45 builtin.c
--- src/builtin.c	19 Oct 2006 23:13:05 -0000	1.1.1.1.2.45
+++ src/builtin.c	26 Oct 2006 21:09:28 -0000
@@ -237,7 +237,7 @@
     free (SYMBOL_TEXT (s));
 
   SYMBOL_TYPE (s) = TOKEN_TEXT;
-  SYMBOL_TEXT (s) = xstrdup (text);
+  SYMBOL_TEXT (s) = xstrdup (text ? text : "");
 }
 
 /*-----------------------------------------------.
@@ -738,7 +738,7 @@
 	  if (TOKEN_DATA_TYPE (argv[i]) != TOKEN_TEXT)
 	    {
 	      TOKEN_DATA_TYPE (argv[i]) = TOKEN_TEXT;
-	      TOKEN_DATA_TEXT (argv[i]) = "";
+	      TOKEN_DATA_TEXT (argv[i]) = (char *) "";
 	    }
       bp->func (obs, argc - 1, argv + 1);
     }
@@ -779,7 +779,7 @@
 	  if (TOKEN_DATA_TYPE (argv[i]) != TOKEN_TEXT)
 	    {
 	      TOKEN_DATA_TYPE (argv[i]) = TOKEN_TEXT;
-	      TOKEN_DATA_TEXT (argv[i]) = "";
+	      TOKEN_DATA_TEXT (argv[i]) = (char *) "";
 	    }
       call_macro (s, argc - 1, argv + 1, obs);
     }
Index: src/format.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/format.c,v
retrieving revision 1.1.1.1.2.5
diff -u -r1.1.1.1.2.5 format.c
--- src/format.c	22 Jul 2006 21:43:27 -0000	1.1.1.1.2.5
+++ src/format.c	26 Oct 2006 21:09:28 -0000
@@ -77,7 +77,7 @@
   char *str;			/* malloc'd buffer of formatted text */
   enum {INT, UINT, LONG, ULONG, DOUBLE, STR} datatype;
 
-  fmt = ARG_STR (argc, argv);
+  fmt = (char *) ARG_STR (argc, argv);
   for (;;)
     {
       while ((c = *fmt++) != '%')
Index: src/m4.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/m4.c,v
retrieving revision 1.1.1.1.2.34
diff -u -r1.1.1.1.2.34 m4.c
--- src/m4.c	13 Oct 2006 22:25:32 -0000	1.1.1.1.2.34
+++ src/m4.c	26 Oct 2006 21:09:28 -0000
@@ -462,9 +462,7 @@
 	{
 	case 'D':
 	  macro_value = strchr (defines->macro, '=');
-	  if (macro_value == NULL)
-	    macro_value = "";
-	  else
+	  if (macro_value)
 	    *macro_value++ = '\0';
 	  define_user_macro (defines->macro, macro_value, SYMBOL_INSERT);
 	  break;
Index: src/macro.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/macro.c,v
retrieving revision 1.1.1.1.2.14
diff -u -r1.1.1.1.2.14 macro.c
--- src/macro.c	11 Oct 2006 17:07:03 -0000	1.1.1.1.2.14
+++ src/macro.c	26 Oct 2006 21:09:28 -0000
@@ -247,7 +247,7 @@
 	  if (!groks_macro_args && TOKEN_DATA_TYPE (&td) == TOKEN_FUNC)
 	    {
 	      TOKEN_DATA_TYPE (&td) = TOKEN_TEXT;
-	      TOKEN_DATA_TEXT (&td) = "";
+	      TOKEN_DATA_TEXT (&td) = (char *) "";
 	    }
 	  tdp = (token_data *) obstack_copy (arguments, &td, sizeof td);
 	  obstack_ptr_grow (argptr, tdp);
@@ -351,7 +351,7 @@
 
   argc = ((obstack_object_size (&argv_stack) - argv_base)
 	  / sizeof (token_data *));
-  argv = (token_data **) (obstack_base (&argv_stack) + argv_base);
+  argv = (token_data **) ((char *) obstack_base (&argv_stack) + argv_base);
 
   loc_close_file = current_file;
   loc_close_line = current_line;
Index: src/output.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/output.c,v
retrieving revision 1.1.1.1.2.12
diff -u -r1.1.1.1.2.12 output.c
--- src/output.c	26 Oct 2006 04:45:31 -0000	1.1.1.1.2.12
+++ src/output.c	26 Oct 2006 21:09:28 -0000
@@ -379,7 +379,7 @@
 		    current_line, output_current_line);
 #endif
 
-	    /* Output a `#line NUM' synchronisation directive if needed.
+	    /* Output a `#line NUM' synchronization directive if needed.
 	       If output_current_line was previously given a negative
 	       value (invalidated), rather output `#line NUM "FILE"'.  */
 
@@ -585,7 +585,11 @@
 	      fflush (diversion->file);
 	      if (fstat (fileno (diversion->file), &file_stat) < 0)
 		M4ERROR ((EXIT_FAILURE, errno, "cannot stat diversion"));
-	      fprintf (file, "D%d,%d", divnum, (int) file_stat.st_size);
+	      if (file_stat.st_size < 0
+		  || file_stat.st_size != (unsigned long) file_stat.st_size)
+		M4ERROR ((EXIT_FAILURE, 0, "diversion too large"));
+	      fprintf (file, "D%d,%lu", divnum,
+		       (unsigned long int) file_stat.st_size);
 	    }
 	  else
 	    fprintf (file, "D%d,%d\n", divnum, diversion->used);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.