]> Shamusworld >> Repos - rmac/commitdiff
Fixed compiler not checking for INCBIN in BSS sections.
authorShamus Hammons <jlhamm@acm.org>
Sat, 2 Feb 2013 21:04:59 +0000 (15:04 -0600)
committerShamus Hammons <jlhamm@acm.org>
Sat, 2 Feb 2013 21:04:59 +0000 (15:04 -0600)
Apparently the compiler did not care if an INCBIN happened in a BSS
section or not. Now the compiler cares and gives an error if you try to
do this terrible, terrible thing. :-D

direct.c
sect.c

index d3e03031d51a108855632ec7aa9d55af2c3df6dd..4a9311c816d7dae54010af3ee7625a7ed85ccbf8 100644 (file)
--- a/direct.c
+++ b/direct.c
@@ -333,6 +333,13 @@ int d_incbin(void)
        long pos, size;
        char buf;
 
+       // Check to see if we're in BSS, and, if so, throw an error
+       if (scattr & SBSS)
+       {
+               errors("Cannot include binary file \"%s\" in BSS section", string[tok[1]]);
+               return ERROR;
+       }
+
        if (*tok != STRING)
        {
                error(syntax_error);
@@ -345,7 +352,12 @@ int d_incbin(void)
                size = lseek(j, 0L, SEEK_END);
                chcheck(size);
                pos = lseek(j, 0L, SEEK_SET);
-               
+
+               DEBUG
+               {
+                       printf("INCBIN: File '%s' is %li bytes.\n", string[tok[1]], size);
+               }
+
                for(i=0; i<size; i++)
                {
                        buf = '\0';
diff --git a/sect.c b/sect.c
index 1046588fd31e073351f6d363beb75e74a4da5a20..d50d9f3ffc997aebae45dbf8e7fae2148cdf5fb6 100644 (file)
--- a/sect.c
+++ b/sect.c
@@ -210,6 +210,7 @@ int fixtest(int sno, LONG loc)
 //
 int chcheck(LONG amt)
 {
+       DEBUG { printf("chcheck(%u)\n", amt); }
        // If in BSS section, no allocation required
        if (scattr & SBSS)
                return 0;
@@ -217,12 +218,14 @@ int chcheck(LONG amt)
        if (!amt)
                amt = CH_THRESHOLD;
 
+       DEBUG { printf("    challoc=%i, ch_size=%i, diff=%i\n", challoc, ch_size, challoc-ch_size); }
        if ((int)(challoc - ch_size) >= (int)amt) 
                return 0;
 
        if (amt < CH_CODE_SIZE)
                amt = CH_CODE_SIZE;
 
+       DEBUG { printf("    amt (adjusted)=%u\n", amt); }
        SECT * p = &sect[cursect];
        CHUNK * cp = malloc(sizeof(CHUNK) + amt);