bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tiny change: s/fputs/fprintf/


From: Paul Eggert
Subject: Re: tiny change: s/fputs/fprintf/
Date: Sun, 07 May 2006 01:18:26 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

Jim Meyering <address@hidden> writes:

> 2006-05-07  Jim Meyering  <address@hidden>
>
>       * src/diff3.c (output_diff3): Use fputs in place of fprintf
>       to avoid warning from gcc -Wformat-security.

Thanks, I don't recall seeing that.

That brought back memories of the bad old days with SunOS bugs!
I installed this more-general patch.

2006-05-07  Paul Eggert  <address@hidden>

        * src/context.c (pr_context_hunk, pr_unidiff_hunk):
        Prefer fputs or fputc to fprintf, since it's a tad more efficient
        with unlocked-IO on glibc.  Long ago we avoided fputs to
        work around an ancient SunOS bug, but that's no longer relevant.
        * src/diff3.c (output_diff3, dotlines, undotlines):
        (output_diff3_edscript, output_diff3_merge): Likewise.
        This also avoids a gcc -Wformat-security warning reported
        by Jim Meyering.
        * src/ed.c (print_ed_hunk, print_forward_ed_hunk, print_rcs_hunk):
        Likewise.
        * src/normal.c (print_normal_hunk): Likewise.

Index: src/context.c
===================================================================
RCS file: /cvsroot/diffutils/diffutils/src/context.c,v
retrieving revision 1.17
diff -p -u -r1.17 context.c
--- src/context.c       5 Jan 2006 07:23:55 -0000       1.17
+++ src/context.c       7 May 2006 08:11:53 -0000
@@ -183,14 +183,14 @@ pr_context_hunk (struct change *hunk)
   begin_output ();
   out = outfile;
 
-  fprintf (out, "***************");
+  fputs ("***************", out);
 
   if (function)
     print_context_function (out, function);
 
-  fprintf (out, "\n*** ");
+  fputs ("\n*** ", out);
   print_context_number_range (&files[0], first0, last0);
-  fprintf (out, " ****\n");
+  fputs (" ****\n", out);
 
   if (changes & OLD)
     {
@@ -217,9 +217,9 @@ pr_context_hunk (struct change *hunk)
        }
     }
 
-  fprintf (out, "--- ");
+  fputs ("--- ", out);
   print_context_number_range (&files[1], first1, last1);
-  fprintf (out, " ----\n");
+  fputs (" ----\n", out);
 
   if (changes & NEW)
     {
@@ -313,11 +313,11 @@ pr_unidiff_hunk (struct change *hunk)
   begin_output ();
   out = outfile;
 
-  fprintf (out, "@@ -");
+  fputs ("@@ -", out);
   print_unidiff_number_range (&files[0], first0, last0);
-  fprintf (out, " +");
+  fputs (" +", out);
   print_unidiff_number_range (&files[1], first1, last1);
-  fprintf (out, " @@");
+  fputs (" @@", out);
 
   if (function)
     print_context_function (out, function);
Index: src/diff3.c
===================================================================
RCS file: /cvsroot/diffutils/diffutils/src/diff3.c,v
retrieving revision 1.46
diff -p -u -r1.46 diff3.c
--- src/diff3.c 13 Mar 2006 19:11:17 -0000      1.46
+++ src/diff3.c 7 May 2006 08:11:53 -0000
@@ -1406,7 +1406,7 @@ output_diff3 (FILE *outputfile, struct d
              line = 0;
              do
                {
-                 fprintf (outputfile, line_prefix);
+                 fputs (line_prefix, outputfile);
                  cp = D_RELNUM (ptr, realfile, line);
                  length = D_RELLEN (ptr, realfile, line);
                  fwrite (cp, sizeof (char), length, outputfile);
@@ -1438,7 +1438,7 @@ dotlines (FILE *outputfile, struct diff3
       if (line[0] == '.')
        {
          leading_dot = true;
-         fprintf (outputfile, ".");
+         fputc ('.', outputfile);
        }
       fwrite (line, sizeof (char),
              D_RELLEN (b, filenum, i), outputfile);
@@ -1455,7 +1455,7 @@ dotlines (FILE *outputfile, struct diff3
 static void
 undotlines (FILE *outputfile, bool leading_dot, long int start, lin num)
 {
-  fprintf (outputfile, ".\n");
+  fputs (".\n", outputfile);
   if (leading_dot)
     {
       if (num == 1)
@@ -1534,7 +1534,7 @@ output_diff3_edscript (FILE *outputfile,
                  leading_dot = dotlines (outputfile, b, mapping[FILE1]);
                }
              /* Append lines from FILE2.  */
-             fprintf (outputfile, "=======\n");
+             fputs ("=======\n", outputfile);
              leading_dot |= dotlines (outputfile, b, mapping[FILE2]);
            }
          fprintf (outputfile, ">>>>>>> %s\n", file2);
@@ -1552,7 +1552,7 @@ output_diff3_edscript (FILE *outputfile,
            {
              /* Prepend lines from FILE1.  */
              leading_dot = dotlines (outputfile, b, mapping[FILE1]);
-             fprintf (outputfile, "=======\n");
+             fputs ("=======\n", outputfile);
            }
          undotlines (outputfile, leading_dot, low0 + 1,
                      D_NUMLINES (b, mapping[FILE1]));
@@ -1585,7 +1585,8 @@ output_diff3_edscript (FILE *outputfile,
                      low0, D_NUMLINES (b, mapping[FILE2]));
        }
     }
-  if (finalwrite) fprintf (outputfile, "w\nq\n");
+  if (finalwrite)
+    fputs ("w\nq\n", outputfile);
   return conflicts_found;
 }
 
@@ -1676,7 +1677,7 @@ output_diff3_merge (FILE *infile, FILE *
                        D_RELLEN (b, mapping[FILE1], i), outputfile);
            }
 
-         fprintf (outputfile, "=======\n");
+         fputs ("=======\n", outputfile);
        }
 
       /* Put in lines from FILE2.  */
Index: src/ed.c
===================================================================
RCS file: /cvsroot/diffutils/diffutils/src/ed.c,v
retrieving revision 1.9
diff -p -u -r1.9 ed.c
--- src/ed.c    5 Jan 2006 07:23:55 -0000       1.9
+++ src/ed.c    7 May 2006 08:11:53 -0000
@@ -1,7 +1,7 @@
 /* Output routines for ed-script format.
 
-   Copyright (C) 1988, 1989, 1991, 1992, 1993, 1995, 1998, 2001, 2004
-   Free Software Foundation, Inc.
+   Copyright (C) 1988, 1989, 1991, 1992, 1993, 1995, 1998, 2001, 2004,
+   2006 Free Software Foundation, Inc.
 
    This file is part of GNU DIFF.
 
@@ -55,7 +55,8 @@ print_ed_hunk (struct change *hunk)
 
   /* Print out the line number header for this hunk */
   print_number_range (',', &files[0], f0, l0);
-  fprintf (outfile, "%c\n", change_letter[changes]);
+  fputc (change_letter[changes], outfile);
+  fputc ('\n', outfile);
 
   /* Print new/changed lines from second file, if needed */
   if (changes != OLD)
@@ -67,7 +68,7 @@ print_ed_hunk (struct change *hunk)
        {
          if (!insert_mode)
            {
-             fprintf (outfile, "a\n");
+             fputs ("a\n", outfile);
              insert_mode = true;
            }
          if (files[1].linbuf[i][0] == '.' && files[1].linbuf[i][1] == '\n')
@@ -75,7 +76,7 @@ print_ed_hunk (struct change *hunk)
              /* The file's line is just a dot, and it would exit
                 insert mode.  Precede the dot with another dot, exit
                 insert mode and remove the extra dot.  */
-             fprintf (outfile, "..\n.\ns/.//\n");
+             fputs ("..\n.\ns/.//\n", outfile);
              insert_mode = false;
            }
          else
@@ -83,7 +84,7 @@ print_ed_hunk (struct change *hunk)
        }
 
       if (insert_mode)
-       fprintf (outfile, ".\n");
+       fputs (".\n", outfile);
     }
 }
 
@@ -111,9 +112,9 @@ pr_forward_ed_hunk (struct change *hunk)
 
   begin_output ();
 
-  fprintf (outfile, "%c", change_letter[changes]);
+  fputc (change_letter[changes], outfile);
   print_number_range (' ', files, f0, l0);
-  fprintf (outfile, "\n");
+  fputc ('\n', outfile);
 
   /* If deletion only, print just the number range.  */
 
@@ -126,7 +127,7 @@ pr_forward_ed_hunk (struct change *hunk)
   for (i = f1; i <= l1; i++)
     print_1_line ("", &files[1].linbuf[i]);
 
-  fprintf (outfile, ".\n");
+  fputs (".\n", outfile);
 }
 
 /* Print in a format somewhat like ed commands
@@ -158,19 +159,16 @@ print_rcs_hunk (struct change *hunk)
 
   if (changes & OLD)
     {
-      fprintf (outfile, "d");
       /* For deletion, print just the starting line number from file 0
         and the number of lines deleted.  */
-      fprintf (outfile, "%ld %ld\n", tf0, tf0 <= tl0 ? tl0 - tf0 + 1 : 1);
+      fprintf (outfile, "d%ld %ld\n", tf0, tf0 <= tl0 ? tl0 - tf0 + 1 : 1);
     }
 
   if (changes & NEW)
     {
-      fprintf (outfile, "a");
-
       /* Take last-line-number from file 0 and # lines from file 1.  */
       translate_range (&files[1], f1, l1, &tf1, &tl1);
-      fprintf (outfile, "%ld %ld\n", tl0, tf1 <= tl1 ? tl1 - tf1 + 1 : 1);
+      fprintf (outfile, "a%ld %ld\n", tl0, tf1 <= tl1 ? tl1 - tf1 + 1 : 1);
 
       /* Print the inserted lines.  */
       for (i = f1; i <= l1; i++)
Index: src/normal.c
===================================================================
RCS file: /cvsroot/diffutils/diffutils/src/normal.c,v
retrieving revision 1.7
diff -p -u -r1.7 normal.c
--- src/normal.c        5 Jan 2006 07:23:55 -0000       1.7
+++ src/normal.c        7 May 2006 08:11:53 -0000
@@ -1,7 +1,7 @@
 /* Normal-format output routines for GNU DIFF.
 
-   Copyright (C) 1988, 1989, 1993, 1995, 1998, 2001 Free Software
-   Foundation, Inc.
+   Copyright (C) 1988, 1989, 1993, 1995, 1998, 2001, 2006 Free
+   Software Foundation, Inc.
 
    This file is part of GNU DIFF.
 
@@ -52,9 +52,9 @@ print_normal_hunk (struct change *hunk)
 
   /* Print out the line number header for this hunk */
   print_number_range (',', &files[0], first0, last0);
-  fprintf (outfile, "%c", change_letter[changes]);
+  fputc (change_letter[changes], outfile);
   print_number_range (',', &files[1], first1, last1);
-  fprintf (outfile, "\n");
+  fputc ('\n', outfile);
 
   /* Print the lines that the first file has.  */
   if (changes & OLD)
@@ -62,7 +62,7 @@ print_normal_hunk (struct change *hunk)
       print_1_line ("<", &files[0].linbuf[i]);
 
   if (changes == CHANGED)
-    fprintf (outfile, "---\n");
+    fputs ("---\n", outfile);
 
   /* Print the lines that the second file has.  */
   if (changes & NEW)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]