ccollins476ad commented on a change in pull request #2073: sys/flash_map: Keep 
non-overlapping default areas
URL: https://github.com/apache/mynewt-core/pull/2073#discussion_r339815077
 
 

 ##########
 File path: sys/flash_map/src/flash_map.c
 ##########
 @@ -406,6 +406,84 @@ flash_map_read_mfg(int max_areas,
     }
 }
 
+/**
+ * Determines if the specified flash area overlaps any areas in the flash map.
+ *
+ * @param area1                 The flash area to compare against the flash
+ *                                  map.
+ *
+ * @return                      True if there is an overlap; false otherwise.
+ */
+static bool
+flash_map_area_overlaps(const struct flash_area *area1)
+{
+    const struct flash_area *area2;
+    uint32_t end1;
+    uint32_t end2;
+    int i;
+
+    for (i = 0; i < flash_map_entries; i++) {
+        area2 = &flash_map[i];
+
+        if (area1->fa_device_id == area2->fa_device_id) {
+            end1 = area1->fa_off + area1->fa_size;
+            end2 = area2->fa_off + area2->fa_size;
+
+            if (end1 >= area2->fa_off && area1->fa_off < end2) {
 
 Review comment:
   I don't think so, but I often mess things things up so I could be wrong.
   
   `fa_off` is the first byte in the flash area.  This byte is actually inside 
the flash area, so there is an overlap if another area uses this byte.
   
   `end` is *one past* the end of the area.  If an area's end is equal to 
another's off, the two areas are adjacent, but not overlapping.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to