lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev [PATCH][dev19] Malloc checks, duplicate #includes, useless code


From: John Bley
Subject: lynx-dev [PATCH][dev19] Malloc checks, duplicate #includes, useless code
Date: Thu, 4 Mar 1999 16:41:55 -0500 (EST)

Pile of malloc checks, some #includes that don't need to exist, and somebody 
decided to waste instructions setting fields to 0 when he already 
memset()ed the whole struct to 0.

-- 
John Bley - address@hidden
Duke '99 - English/Computer Science
  Since English is a mess, it maps well onto the problem space,
  which is also a mess, which we call reality.     - Larry Wall

diff -Burp lynx2-8-2/WWW/Library/Implementation/HTAAServ.c 
lynx2-8-2-patched/WWW/Library/Implementation/HTAAServ.c
--- lynx2-8-2/WWW/Library/Implementation/HTAAServ.c     Thu Dec 24 06:27:23 1998
+++ lynx2-8-2-patched/WWW/Library/Implementation/HTAAServ.c     Thu Mar  4 
16:10:36 1999
@@ -437,6 +437,8 @@ PUBLIC int HTAA_checkAuthorization ARGS4
                    *end = '\0';
                FREE(pathname);
                pathname=(char*)malloc(strlen(HTBinDir)+strlen(local_copy)+1);
+               if (pathname == NULL)
+                   outofmem(__FILE__, "HTAA_checkAuthorization");
                strcpy(pathname, HTBinDir);
                strcat(pathname, local_copy+6);
            }
diff -Burp lynx2-8-2/WWW/Library/Implementation/HTAccess.c 
lynx2-8-2-patched/WWW/Library/Implementation/HTAccess.c
--- lynx2-8-2/WWW/Library/Implementation/HTAccess.c     Thu Mar  4 05:39:45 1999
+++ lynx2-8-2-patched/WWW/Library/Implementation/HTAccess.c     Thu Mar  4 
16:07:39 1999
@@ -55,12 +55,10 @@
 
 #include <HTList.h>
 #include <HText.h>     /* See bugs above */
-#include <HTAlert.h>
 #include <HTCJK.h>
 #include <UCMap.h>
 #include <GridText.h>
 
-#include <GridText.h>
 #include <LYGlobalDefs.h>
 #include <LYexit.h>
 #include <LYUtils.h>
diff -Burp lynx2-8-2/WWW/Library/Implementation/HTAnchor.c 
lynx2-8-2-patched/WWW/Library/Implementation/HTAnchor.c
--- lynx2-8-2/WWW/Library/Implementation/HTAnchor.c     Thu Mar  4 05:39:45 1999
+++ lynx2-8-2-patched/WWW/Library/Implementation/HTAnchor.c     Thu Mar  4 
16:11:57 1999
@@ -372,6 +372,8 @@ PUBLIC HTAnchor * HTAnchor_findAddress A
        hash = HASH_FUNCTION(newdoc->address);
        if (!adult_table) {
            adult_table = (HTList **)calloc(HASH_SIZE, sizeof(HTList *));
+           if (!adult_table)
+               outofmem(__FILE__, "HTAnchor_findAddress");
            atexit(free_adult_table);
        }
        if (!adult_table[hash])
diff -Burp lynx2-8-2/WWW/Library/Implementation/HTFTP.c 
lynx2-8-2-patched/WWW/Library/Implementation/HTFTP.c
--- lynx2-8-2/WWW/Library/Implementation/HTFTP.c        Wed Feb 17 09:29:33 1999
+++ lynx2-8-2-patched/WWW/Library/Implementation/HTFTP.c        Thu Mar  4 
16:12:34 1999
@@ -1891,6 +1891,8 @@ PRIVATE EntryInfo * parse_dir_entry ARGS
     char *cp;
 
     entry_info = (EntryInfo *)malloc(sizeof(EntryInfo));
+    if (entry_info == NULL)
+       outofmem(__FILE__, "parse_dir_entry");
     entry_info->filename = NULL;
     entry_info->type = NULL;
     entry_info->date = NULL;
diff -Burp lynx2-8-2/WWW/Library/Implementation/HTFWriter.c 
lynx2-8-2-patched/WWW/Library/Implementation/HTFWriter.c
--- lynx2-8-2/WWW/Library/Implementation/HTFWriter.c    Thu Dec 24 06:27:23 1998
+++ lynx2-8-2-patched/WWW/Library/Implementation/HTFWriter.c    Thu Mar  4 
16:13:52 1999
@@ -251,6 +251,8 @@ PUBLIC HTStream* HTSaveAndExecute ARGS3(
     suffix = HTFileSuffix(pres->rep, anchor->content_encoding);
 
     fnam = (char *)malloc (L_tmpnam + 16 + strlen(suffix));
+    if (fnam == NULL)
+       outofmem(__FILE__, "HTSaveAndExecute");
     tmpnam (fnam);
     if (suffix) strcat(fnam, suffix);
     
@@ -321,6 +323,8 @@ PUBLIC HTStream* HTSaveLocally ARGS3(
     suffix = HTFileSuffix(pres->rep, anchor->content_encoding);
 
     fnam = (char *)malloc (L_tmpnam + 16 + strlen(suffix));
+    if (fnam == NULL)
+       outofmem(__FILE__, "HTSaveLocally");
     tmpnam (fnam);
     if (suffix) strcat(fnam, suffix);
     
diff -Burp lynx2-8-2/WWW/Library/Implementation/HTFormat.c 
lynx2-8-2-patched/WWW/Library/Implementation/HTFormat.c
--- lynx2-8-2/WWW/Library/Implementation/HTFormat.c     Wed Feb 17 09:29:33 1999
+++ lynx2-8-2-patched/WWW/Library/Implementation/HTFormat.c     Thu Mar  4 
16:06:12 1999
@@ -41,7 +41,6 @@ PUBLIC long int HTMaxBytes  = 0;      /* No e
 #include <HTFWriter.h>
 #include <HTPlain.h>
 #include <SGML.h>
-#include <HTML.h>
 #include <HTMLGen.h>
 
 #include <LYexit.h>
diff -Burp lynx2-8-2/WWW/Library/Implementation/HTGroup.c 
lynx2-8-2-patched/WWW/Library/Implementation/HTGroup.c
--- lynx2-8-2/WWW/Library/Implementation/HTGroup.c      Sat Dec 12 23:10:36 1998
+++ lynx2-8-2-patched/WWW/Library/Implementation/HTGroup.c      Thu Mar  4 
16:17:28 1999
@@ -108,6 +108,8 @@ PRIVATE AddressDefList *parse_address_pa
 
     for(;;) {
        Ref *ref = (Ref*)calloc(1, sizeof(Ref));
+       if (ref == NULL)
+           outofmem(__FILE__, "parse_address_part");
        ref->name = NULL;
        ref->translation = NULL;
        StrAllocCopy(ref->name, HTlex_buffer);
@@ -162,6 +164,8 @@ PRIVATE UserDefList *parse_user_part ARG
 
     for (;;) {
        Ref *ref = (Ref*)calloc(1, sizeof(Ref));
+       if (ref == NULL)
+           outofmem(__FILE__, "parse_user_part");
        ref->name = NULL;
        ref->translation = NULL;
        StrAllocCopy(ref->name, HTlex_buffer);
@@ -235,6 +239,8 @@ PRIVATE Item *parse_item ARGS1(FILE *, f
        return NULL;
     }
     item = (Item*)calloc(1, sizeof(Item));
+    if (item == NULL)
+       outofmem(__FILE__, "parse_item");
     item->user_def_list = user_def_list;
     item->address_def_list = address_def_list;
     return item;
@@ -282,6 +288,8 @@ PUBLIC GroupDef *HTAA_parseGroupDef ARGS
        return NULL;
     }
     group_def = (GroupDef*)calloc(1, sizeof(GroupDef));
+    if (group_def == NULL)
+       outofmem(__FILE__, "HTAA_parseGroupDef");
     group_def->group_name = NULL;
     group_def->item_list = item_list;
 
diff -Burp lynx2-8-2/WWW/Library/Implementation/HTStyle.c 
lynx2-8-2-patched/WWW/Library/Implementation/HTStyle.c
--- lynx2-8-2/WWW/Library/Implementation/HTStyle.c      Thu Dec 24 06:27:23 1998
+++ lynx2-8-2-patched/WWW/Library/Implementation/HTStyle.c      Thu Mar  4 
16:24:57 1999
@@ -19,9 +19,9 @@
 PUBLIC HTStyle* HTStyleNew NOARGS
 {
     HTStyle * self = (HTStyle *)malloc(sizeof(*self));
+    if (self == NULL)
+       outofmem(__FILE__, "HTStyleNew");
     memset((void *)self, 0, sizeof(*self));
-    self->font = (HTFont) 0;
-    self->color = 0;
     return self;
 }
 
@@ -72,6 +72,8 @@ HTStyle * HTStyleRead (HTStyle * style, 
     if (gotpara) {
        if (!style->paragraph) {
            style->paragraph = malloc(sizeof(*(style->paragraph)));
+           if (!style->paragraph)
+               outofmem(__FILE__, "HTStyleRead");
            style->paragraph->tabs = 0;
        }
        p = style->paragraph;
@@ -86,6 +88,8 @@ HTStyle * HTStyleRead (HTStyle * style, 
            &p->numTabs);
        FREE(p->tabs);
        p->tabs = malloc(p->numTabs * sizeof(p->tabs[0]));
+       if (!p->tabs)
+           outofmem(__FILE__, "HTStyleRead");
        for (tab=0; tab < p->numTabs; tab++) {
            NXScanf(stream, "%hd%f",
                    &p->tabs[tab].kind,
@@ -284,6 +288,8 @@ HTStyleSheet * HTStyleSheetRemoveStyle A
 HTStyleSheet * HTStyleSheetNew NOARGS
 {
     HTStyleSheet * self = (HTStyleSheet *)malloc(sizeof(*self));
+    if (self == NULL)
+       outofmem(__FILE__, "HTStyleSheetNew");
 
     memset((void*)self, 0, sizeof(*self));     /* ANSI */
 /* Harbison c ref man says (char*)self
diff -Burp lynx2-8-2/WWW/Library/Implementation/HTTP.c 
lynx2-8-2-patched/WWW/Library/Implementation/HTTP.c
--- lynx2-8-2/WWW/Library/Implementation/HTTP.c Thu Jan 28 11:31:29 1999
+++ lynx2-8-2-patched/WWW/Library/Implementation/HTTP.c Thu Mar  4 16:28:13 1999
@@ -650,6 +650,8 @@ try_again:
     int buffer_length = INIT_LINE_SIZE;
 
     line_buffer = (char *)calloc(1, (buffer_length * sizeof(char)));
+    if (line_buffer == NULL)
+       outofmem(__FILE__, "HTLoadHTTP");
 
     HTReadProgress (bytes_already_read = 0, 0);
     do {/* Loop to read in the first line */
@@ -660,6 +662,8 @@ try_again:
            buffer_length = buffer_length + buffer_length;
            line_buffer =
              (char *)realloc(line_buffer, (buffer_length * sizeof(char)));
+           if (line_buffer == NULL)
+               outofmem(__FILE__, "HTLoadHTTP");
        }
        CTRACE (tfp, "HTTP: Trying to read %d\n",
                     buffer_length - length - 1);
@@ -729,6 +733,8 @@ try_again:
        if (line_buffer) {
            FREE(line_kept_clean);
            line_kept_clean = (char *)malloc(buffer_length * sizeof(char));
+           if (line_kept_clean == NULL)
+               outofmem(__FILE__, "HTLoadHTTP");
            memcpy(line_kept_clean, line_buffer, buffer_length);
        }
 
diff -Burp lynx2-8-2/src/LYLocal.c lynx2-8-2-patched/src/LYLocal.c
--- lynx2-8-2/src/LYLocal.c     Wed Feb 17 09:29:33 1999
+++ lynx2-8-2-patched/src/LYLocal.c     Thu Mar  4 15:49:17 1999
@@ -1878,6 +1878,8 @@ PUBLIC void add_menu_item ARGS1(
        menu_head = NULL;
 
     new = (struct dired_menu *)calloc(1, sizeof(*new));
+    if (new == NULL)
+       outofmem(__FILE__, "add_menu_item");
 
     /*
      * Conditional on tagged != NULL ?

reply via email to

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