]> sjero.net Git - wget/blobdiff - src/log.c
[svn] Don't cast return type of malloc/realloc. Assume ANSI C signal handlers.
[wget] / src / log.c
index 2a9d586372ebbc85e5aaa4537ce1662493acc7c8..d0b5370a432e4f27cab1d6053fc6f9d4a745ce78 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -30,17 +30,9 @@ so, delete this exception statement from your version.  */
 #include <config.h>
 
 #include <stdio.h>
-#ifdef HAVE_STRING_H
-# include <string.h>
-#else
-# include <strings.h>
-#endif
+#include <string.h>
 #include <stdlib.h>
-#ifdef WGET_USE_STDARG
-# include <stdarg.h>
-#else
-# include <varargs.h>
-#endif
+#include <stdarg.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
@@ -51,10 +43,6 @@ so, delete this exception statement from your version.  */
 #include "utils.h"
 #include "log.h"
 
-#ifndef errno
-extern int errno;
-#endif
-
 /* This file impplement support for "logging".  Logging means printing
    output, plus several additional features:
 
@@ -137,7 +125,7 @@ static int log_line_current = -1;
    than create new ones.  */
 static int trailing_line;
 
-static void check_redirect_output PARAMS ((void));
+static void check_redirect_output (void);
 \f
 #define ROT_ADVANCE(num) do {                  \
   if (++num >= SAVED_LOG_LINES)                        \
@@ -220,7 +208,7 @@ saved_append_1 (const char *start, const char *end)
            {
              /* Allocate memory and concatenate the old and the new
                  contents. */
-             ln->malloced_line = (char *)xmalloc (old_len + len + 1);
+             ln->malloced_line = xmalloc (old_len + len + 1);
              memcpy (ln->malloced_line, ln->static_line,
                      old_len);
              memcpy (ln->malloced_line + old_len, start, len);
@@ -466,16 +454,6 @@ log_set_save_context (int savep)
   return old;
 }
 
-/* Handle difference in va_start between pre-ANSI and ANSI C.  Note
-   that we always use `...' in function definitions and let ansi2knr
-   convert it for us.  */
-
-#ifdef WGET_USE_STDARG
-# define VA_START(args, arg1) va_start (args, arg1)
-#else
-# define VA_START(args, ignored) va_start (args)
-#endif
-
 /* Print a message to the screen or to the log.  The first argument
    defines the verbosity of the message, and the rest are as in
    printf(3).  */
@@ -495,7 +473,7 @@ logprintf (enum log_options o, const char *fmt, ...)
   xzero (lpstate);
   do
     {
-      VA_START (args, fmt);
+      va_start (args, fmt);
       done = log_vprintf_internal (&lpstate, fmt, args);
       va_end (args);
     }
@@ -521,7 +499,7 @@ debug_logprintf (const char *fmt, ...)
       xzero (lpstate);
       do
        {
-         VA_START (args, fmt);
+         va_start (args, fmt);
          done = log_vprintf_internal (&lpstate, fmt, args);
          va_end (args);
        }
@@ -704,10 +682,11 @@ static const char *
 escnonprint_internal (const char *str, char escape, int base)
 {
   static int ringpos;                  /* current ring position */
+  int nprcnt;
 
   assert (base == 8 || base == 16);
 
-  int nprcnt = count_nonprint (str);
+  nprcnt = count_nonprint (str);
   if (nprcnt == 0)
     /* If there are no non-printable chars in STR, don't bother
        copying anything, just return STR.  */
@@ -743,6 +722,18 @@ escnonprint_internal (const char *str, char escape, int base)
    characters in STR, STR is returned.  See copy_and_escape for more
    information on which characters are considered non-printable.
 
+   DON'T call this function on translated strings because escaping
+   will break them.  Don't call it on literal strings from the source,
+   which are by definition trusted.  If newlines are allowed in the
+   string, escape and print it line by line because escaping the whole
+   string will convert newlines to \012.  (This is so that expectedly
+   single-line messages cannot use embedded newlines to mimic Wget's
+   output and deceive the user.)
+
+   escnonprint doesn't quote its escape character because it is notf
+   meant as a general and reversible quoting mechanism, but as a quick
+   way to defang binary junk sent by malicious or buggy servers.
+
    NOTE: since this function can return a pointer to static data, be
    careful to copy its result before calling it again.  However, to be
    more useful with printf, it maintains an internal ring of static
@@ -758,11 +749,9 @@ escnonprint (const char *str)
 
 /* Return a pointer to a static copy of STR with the non-printable
    characters escaped as %XX.  If there are no non-printable
-   characters in STR, STR is returned.  See copy_and_escape for more
-   information on which characters are considered non-printable.
+   characters in STR, STR is returned.
 
-   This function returns a pointer to static data which will be
-   overwritten by subsequent calls -- see escnonprint for details.  */
+   See escnonprint for usage details.  */
 
 const char *
 escnonprint_uri (const char *str)