]> sjero.net Git - wget/commitdiff
[svn] Use alloca to allocate filename_plus_orig_suffix.
authorhniksic <devnull@localhost>
Sat, 28 Apr 2001 16:36:46 +0000 (09:36 -0700)
committerhniksic <devnull@localhost>
Sat, 28 Apr 2001 16:36:46 +0000 (09:36 -0700)
Published in <sxsu239htnl.fsf@florida.arsdigita.de>.

src/ChangeLog
src/http.c

index 21f675a3ca9cd1420dc4952cb77459da32f2157a..f5b70250b038db192415b7722ef2a02dce4530e5 100644 (file)
@@ -1,3 +1,9 @@
+2001-04-28  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       (http_loop): Allocate space for filename_plus_orig_suffix with
+       alloca; this is more efficient and removes the need to free it
+       before each and every return.
+
 2001-04-28  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * http.c (gethttp): Return RETRUNNEEDED when the retrieval is
index 9f6cb4953fa3d1f7db1dc468b9c50bfbffc50454..f595d29210dd25530ba7d9a0e81024c8699388e2 100644 (file)
@@ -1402,11 +1402,8 @@ http_loop (struct urlinfo *u, char **newloc, int *dt)
   else
     locf = opt.output_document;
 
-  /* Yuck.  Multiple returns suck.  We need to remember to free() the space we
-     xmalloc() here before EACH return.  This is one reason it's better to set
-     flags that influence flow control and then return once at the end. */
-  filename_len = strlen(u->local);
-  filename_plus_orig_suffix = xmalloc(filename_len + sizeof(".orig"));
+  filename_len = strlen (u->local);
+  filename_plus_orig_suffix = alloca (filename_len + sizeof (".orig"));
 
   if (opt.noclobber && file_exists_p (u->local))
     {
@@ -1424,7 +1421,6 @@ File `%s' already there, will not retrieve.\n"), u->local);
          && (!strcmp (suf, "html") || !strcmp (suf, "htm")))
        *dt |= TEXTHTML;
       xfree (suf);
-      xfree (filename_plus_orig_suffix); /* must precede every return! */
       /* Another harmless lie: */
       return RETROK;
     }
@@ -1452,11 +1448,12 @@ File `%s' already there, will not retrieve.\n"), u->local);
             in url.c.  Replacing sprintf with inline calls to
             strcpy() and long_to_string() made a difference.
             --hniksic */
-         strcpy(filename_plus_orig_suffix, u->local);
-         strcpy(filename_plus_orig_suffix + filename_len, ".orig");
+         memcpy (filename_plus_orig_suffix, u->local, filename_len);
+         memcpy (filename_plus_orig_suffix + filename_len,
+                 ".orig", sizeof (".orig"));
 
          /* Try to stat() the .orig file. */
-         if (stat(filename_plus_orig_suffix, &st) == 0)
+         if (stat (filename_plus_orig_suffix, &st) == 0)
            {
              local_dot_orig_file_exists = TRUE;
              local_filename = filename_plus_orig_suffix;
@@ -1573,7 +1570,6 @@ File `%s' already there, will not retrieve.\n"), u->local);
        case SSLERRCTXCREATE: case CONTNOTSUPPORTED:
          /* Fatal errors just return from the function.  */
          FREEHSTAT (hstat);
-         xfree (filename_plus_orig_suffix); /* must precede every return! */
          return err;
          break;
        case FWRITEERR: case FOPENERR:
@@ -1589,7 +1585,6 @@ File `%s' already there, will not retrieve.\n"), u->local);
          logputs (LOG_VERBOSE, "\n");
          logprintf (LOG_NOTQUIET, _("Unable to establish SSL connection.\n"));
          FREEHSTAT (hstat);
-         xfree (filename_plus_orig_suffix); /* must precede every return! */
          return err;
          break;
        case NEWLOCATION:
@@ -1599,17 +1594,14 @@ File `%s' already there, will not retrieve.\n"), u->local);
              logprintf (LOG_NOTQUIET,
                         _("ERROR: Redirection (%d) without location.\n"),
                         hstat.statcode);
-             xfree (filename_plus_orig_suffix); /* must precede every return! */
              return WRONGCODE;
            }
          FREEHSTAT (hstat);
-         xfree (filename_plus_orig_suffix); /* must precede every return! */
          return NEWLOCATION;
          break;
        case RETRUNNEEDED:
          /* The file was already fully retrieved. */
          FREEHSTAT (hstat);
-         xfree (filename_plus_orig_suffix); /* must precede every return! */
          return RETROK;
          break;
        case RETRFINISHED:
@@ -1632,7 +1624,6 @@ File `%s' already there, will not retrieve.\n"), u->local);
                     tms, hstat.statcode, hstat.error);
          logputs (LOG_VERBOSE, "\n");
          FREEHSTAT (hstat);
-         xfree (filename_plus_orig_suffix); /* must precede every return! */
          return WRONGCODE;
        }
 
@@ -1676,7 +1667,6 @@ Last-modified header invalid -- time-stamp ignored.\n"));
 Server file no newer than local file `%s' -- not retrieving.\n\n"),
                             local_filename);
                  FREEHSTAT (hstat);
-                 xfree (filename_plus_orig_suffix); /*must precede every return!*/
                  return RETROK;
                }
              else if (tml >= tmr)
@@ -1714,7 +1704,6 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
       if (opt.spider)
        {
          logprintf (LOG_NOTQUIET, "%d %s\n\n", hstat.statcode, hstat.error);
-         xfree (filename_plus_orig_suffix); /* must precede every return! */
          return RETROK;
        }
 
@@ -1744,7 +1733,6 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
          else
            downloaded_file(FILE_DOWNLOADED_NORMALLY, locf);
 
-         xfree(filename_plus_orig_suffix); /* must precede every return! */
          return RETROK;
        }
       else if (hstat.res == 0) /* No read error */
@@ -1770,7 +1758,6 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
              else
                downloaded_file(FILE_DOWNLOADED_NORMALLY, locf);
              
-             xfree (filename_plus_orig_suffix); /* must precede every return! */
              return RETROK;
            }
          else if (hstat.len < hstat.contlen) /* meaning we lost the
@@ -1799,7 +1786,6 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
              else
                downloaded_file(FILE_DOWNLOADED_NORMALLY, locf);
              
-             xfree (filename_plus_orig_suffix); /* must precede every return! */
              return RETROK;
            }
          else                  /* the same, but not accepted */
@@ -1835,7 +1821,6 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
       break;
     }
   while (!opt.ntry || (count < opt.ntry));
-  xfree (filename_plus_orig_suffix); /* must precede every return! */
   return TRYLIMEXC;
 }
 \f