Fix datagram overflow layout issue
authorDave Page <dave.page@gleeble.com>
Tue, 07 Apr 2015 21:07:16 -0400
changeset 2614 9b29d7bfa230
parent 2613 7208f4341104
child 2615 bc34e2303fd6
Fix datagram overflow layout issue
master/domain.c
--- a/master/domain.c	Mon Apr 06 14:58:19 2015 -0400
+++ b/master/domain.c	Tue Apr 07 21:07:16 2015 -0400
@@ -347,7 +347,11 @@
             // As FMMU offsets increase monotonically, and candidate start
             // offset has never been contradicted, it can now never be
             // contradicted, as no future FMMU can cross it.
-            if (candidate_start - datagram_offset > EC_MAX_DATA_SIZE) {
+            // All FMMUs prior to this point approved for next datagram
+            valid_fmmu = fmmu;
+            valid_start = candidate_start;
+            if (fmmu->logical_domain_offset + fmmu->data_size - datagram_offset
+                    > EC_MAX_DATA_SIZE) {
                 // yet the new candidate exceeds the datagram size, so we
                 // use the last known valid candidate to create the datagram
                 ret = emplace_datagram(domain, datagram_offset, valid_start,
@@ -359,9 +363,6 @@
                 datagram_count++;
                 datagram_first_fmmu = fmmu;
             }
-            // All FMMUs prior to this point approved for next datagram
-            valid_fmmu = fmmu;
-            valid_start = candidate_start;
         }
         if (fmmu->logical_domain_offset + fmmu->data_size > candidate_start) {
             candidate_start = fmmu->logical_domain_offset + fmmu->data_size;
@@ -387,9 +388,9 @@
         const ec_datagram_t *datagram =
             &datagram_pair->datagrams[EC_DEVICE_MAIN];
         EC_MASTER_INFO(domain->master, "  Datagram %s: Logical offset 0x%08x,"
-                " %zu byte, type %s.\n", datagram->name,
+                " %zu byte, type %s at %p.\n", datagram->name,
                 EC_READ_U32(datagram->address), datagram->data_size,
-                ec_datagram_type_string(datagram));
+                ec_datagram_type_string(datagram), datagram);
     }
 
     return 0;