Fix cell increment error in RESIZE
authorphil@softsynth.com <phil@softsynth.com@b0a0988d-7f52-0410-8c73-4f6cdee1a2cf>
Wed, 18 Feb 2009 17:59:02 +0000 (17:59 +0000)
committerphil@softsynth.com <phil@softsynth.com@b0a0988d-7f52-0410-8c73-4f6cdee1a2cf>
Wed, 18 Feb 2009 17:59:02 +0000 (17:59 +0000)
csrc/pf_core.c
csrc/pf_inner.c

index 0329749..ceab2be 100644 (file)
@@ -444,7 +444,6 @@ int32 pfDoForth( const char *DicName, const char *SourceName, int32 IfInit )
 \r
        pfInit();\r
        \r
 \r
        pfInit();\r
        \r
-       \r
 /* Allocate Task structure. */\r
        pfDebugMessage("pfDoForth: call pfCreateTask()\n");\r
        cftd = pfCreateTask( DEFAULT_USER_DEPTH, DEFAULT_RETURN_DEPTH );\r
 /* Allocate Task structure. */\r
        pfDebugMessage("pfDoForth: call pfCreateTask()\n");\r
        cftd = pfCreateTask( DEFAULT_USER_DEPTH, DEFAULT_RETURN_DEPTH );\r
index 7b2da55..15f764f 100644 (file)
@@ -1397,12 +1397,13 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql ));
 /* Resize memory allocated by ALLOCATE. */\r
                case ID_RESIZE:  /* ( addr1 u -- addr2 result ) */\r
                        {\r
 /* Resize memory allocated by ALLOCATE. */\r
                case ID_RESIZE:  /* ( addr1 u -- addr2 result ) */\r
                        {\r
-                               cell *FreePtr;\r
-                               \r
-                               FreePtr = (cell *) ( M_POP - sizeof(cell) );\r
+                               cell *Addr1 = (cell *) M_POP;\r
+                               // Point to validator below users address.\r
+                               cell *FreePtr = Addr1 - 1;\r
                                if( ((uint32)*FreePtr) != ((uint32)FreePtr ^ PF_MEMORY_VALIDATOR))\r
                                {\r
                                if( ((uint32)*FreePtr) != ((uint32)FreePtr ^ PF_MEMORY_VALIDATOR))\r
                                {\r
-                                       M_PUSH( 0 );\r
+                                       // 090218 - Fixed bug, was returning zero.\r
+                                       M_PUSH( Addr1 );\r
                                        TOS = -3;\r
                                }\r
                                else\r
                                        TOS = -3;\r
                                }\r
                                else\r
@@ -1414,15 +1415,18 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql ));
                                                /* Copy memory including validation. */\r
                                                pfCopyMemory( (char *) CellPtr, (char *) FreePtr, TOS + sizeof(cell) );\r
                                                *CellPtr = (cell)(((uint32)CellPtr) ^ (uint32)PF_MEMORY_VALIDATOR);\r
                                                /* Copy memory including validation. */\r
                                                pfCopyMemory( (char *) CellPtr, (char *) FreePtr, TOS + sizeof(cell) );\r
                                                *CellPtr = (cell)(((uint32)CellPtr) ^ (uint32)PF_MEMORY_VALIDATOR);\r
-                                               CellPtr++;\r
-                                   M_PUSH( (cell) ++CellPtr );\r
-                                               TOS = 0;\r
+                                               // 090218 - Fixed bug that was incrementing the address twice. Thanks Reinhold Straub.\r
+                                               // Increment past validator to user address.\r
+                                   M_PUSH( (cell) (CellPtr + 1) );\r
+                                               TOS = 0; // Result code.\r
+                                               // Mark old cell as dead so we can't free it twice.\r
                                                FreePtr[0] = 0xDeadBeef;\r
                                                pfFreeMem((char *) FreePtr);\r
                                        }\r
                                        else\r
                                        {\r
                                                FreePtr[0] = 0xDeadBeef;\r
                                                pfFreeMem((char *) FreePtr);\r
                                        }\r
                                        else\r
                                        {\r
-                                               M_PUSH( 0 );\r
+                                               // 090218 - Fixed bug, was returning zero.\r
+                                               M_PUSH( Addr1 );\r
                                                TOS = -4;  /* FIXME Fix error code. */\r
                                        }\r
                                }\r
                                                TOS = -4;  /* FIXME Fix error code. */\r
                                        }\r
                                }\r