groff
[Top][All Lists]
Advanced

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

[Groff] fix for static size buffer problem


From: Gaius Mulley
Subject: [Groff] fix for static size buffer problem
Date: Fri, 16 Aug 2002 13:44:11 +0100

Hi,

here is a better solution to the post-grohtml fixed size buffer problem.
Basically it mallocs a minimum of SIZE chars, if necessary it will
malloc more should we encounter a large string.

Gaius


--- groff-cvs/src/devices/grohtml/post-html.cc  Wed Aug  7 16:01:32 2002
+++ groff-html/src/devices/grohtml/post-html.cc Fri Aug 16 13:30:40 2002
@@ -254,16 +254,25 @@
 
 struct char_block {
   enum { SIZE = 256 };
-  char          buffer[SIZE];
+  char         *buffer;
   int           used;
   char_block   *next;
 
   char_block();
+  char_block::char_block(int length);
 };
 
 char_block::char_block()
+  : used(0), next(0), buffer(NULL)
+{
+}
+
+char_block::char_block(int length)
 : used(0), next(0)
 {
+  buffer = (char *)malloc(max(length, char_block::SIZE));
+  if (buffer == NULL)
+    fatal("out of memory error");
 }
 
 class char_buffer {
@@ -300,17 +309,13 @@
     return NULL;
 
   if (tail == 0) {
-    tail = new char_block;
+    tail = new char_block(length+1);
     head = tail;
   } else {
     if (tail->used + length+1 > char_block::SIZE) {
-      tail->next = new char_block;
-      tail       = tail->next;
+      tail->next  = new char_block(length+1);
+      tail        = tail->next;
     }
-  }
-  // at this point we have a tail which is ready for the string.
-  if (tail->used + length+1 > char_block::SIZE) {
-    fatal("need to increase char_block::SIZE");
   }
 
   old_used = tail->used;

reply via email to

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