]> git.sur5r.net Git - cc65/blobdiff - src/ld65/fragment.c
New module strstack
[cc65] / src / ld65 / fragment.c
index cd4ae6028d1654d0ec051a9680b49c1fc4601482..3f543b33d17f64212248d443b19cd3427368076d 100644 (file)
 
 
 /* common */
+#include "fragdefs.h"
 #include "xmalloc.h"
 
 /* ld65 */
-#include "segments.h"
+#include "error.h"
 #include "fragment.h"
+#include "segments.h"
 
 
 
 
 
 
-Fragment* NewFragment (unsigned char Type, unsigned long Size, Section* S)
+Fragment* NewFragment (unsigned char Type, unsigned Size, Section* S)
 /* Create a new fragment and insert it into the section S */
 {
+    Fragment* F;
+
+    /* Calculate the size of the memory block. LitBuf is only needed if the
+     * fragment contains literal data.
+     */
+    unsigned FragSize = sizeof (Fragment) - 1;
+    if (Type == FRAG_LITERAL) {
+        FragSize += Size;
+    }
+
     /* Allocate memory */
-    Fragment* F = xmalloc (sizeof (Fragment) - 1 + Size);    
+    F = xmalloc (FragSize);
 
     /* Initialize the data */
     F->Next      = 0;
@@ -61,8 +73,6 @@ Fragment* NewFragment (unsigned char Type, unsigned long Size, Section* S)
     F->Expr      = 0;
     InitFilePos (&F->Pos);
     F->LI        = 0;
-    F->WarnExpr  = 0;
-    F->ErrorExpr = 0;
     F->Type      = Type;
 
     /* Insert the code fragment into the section */