eda/edb: Proper fix for http://ecere.com/mantis/view.php?id=646 (fb5b0907e281e269dcb0...
authorJerome St-Louis <jerome@ecere.com>
Sun, 16 Oct 2011 18:59:10 +0000 (14:59 -0400)
committerJerome St-Louis <jerome@ecere.com>
Sun, 16 Oct 2011 18:59:10 +0000 (14:59 -0400)
eda/libeda/src/EDB.ec

index 85c850d..646dd52 100644 (file)
@@ -1047,27 +1047,27 @@ static class EDBRow : DriverRow
             tf.Write(offsets, sizeof(uint), numFields);
 
             size = f.GetSize();
-            // *** Fields are based at index 1, if we're writing the last field we need to set size to its offset
-            // because we will be rewriting over it. ***
-            if(field.num <= oldNumFields)
+            if(field.num-1 < oldNumFields)
             {
                // We will read right up to to the field we're writing to
                // (Size will be from right after the offset table to that offset)
-               int c;
-               for(c = field.num - 1; c >= 0; c--)
-               {
-                  if(offsets[c])
-                  {
-                     // *** I don't know why were incrementing c on init here, because the current field is the offset we want ***
-                     for(; c < oldNumFields; c++)
-                        if(offsets[c])
-                        {
-                           size = offsets[c];
-                           break;
-                        }
-                     break;
-                  }
-               }
+                if(offsets[field.num-1])
+                  // *** Fields are based at index 1, if we're writing the last field we need to set size to its offset
+                  // because we will be rewriting over it. ***
+                  size = offsets[field.num-1];
+                else
+                {
+                   int c;
+                   // If this field does not exist yet (offsets[field.num-1] == 0), we want to write at the end (leave size = f.GetSize()),
+                   for(c = field.num; c < oldNumFields; c++)
+                   {
+                      if(offsets[c])
+                      {
+                         size = offsets[c];
+                         break;
+                      }
+                   }
+                }
             }
 
             // Subtract the header (numFields + offsets table), that's where we're at right now