[riot-notifications] [RIOT-OS/RIOT] sam0_common/periph/flashpage: fix unaligned write (#15707)

Marian Buschsieweke notifications at github.com
Mon Jan 18 18:01:49 CET 2021


@maribu commented on this pull request.



> @@ -223,21 +230,25 @@ static void _write_page(void* dst, const void *data, size_t len, void (*cmd_writ
     _cmd_clear_page_buffer();
 
     /* write the first, unaligned bytes */
-    if (unaligned_start) {
-        *dst32++ = unaligned_pad_start(data, unaligned_start);
-        data = (uint8_t*)data + unaligned_start;
+    if (len_unaligned_start) {
+        *dst32++ = unaligned_pad_start(data, len_unaligned_start,
+                offset_unaligned_start);
+        data = (uint8_t*)data + len_unaligned_start;
     }
 
     /* copy whole words */
     const uint32_t *data32 = data;

An `uint32_t *` should always be aligned to 4 byte to avoid confusion. I'm aware that `unaligned_get_u32()` is used to access data at this address, which is correct. But the pointer type should `uint8_t *` or `void *`, if you're not sure about the alignment. I'm aware that `dst32++` is more readable than `dst32 += sizeof(uint32_t)` (when `uint8_t *` is used) or even `dst32 = (uintptr_t)dst32 + sizeof(uint32_t)` (when `void *` is used). But otherwise this is undefined behavior.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/15707#pullrequestreview-570664277
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210118/994b51ca/attachment.htm>


More information about the notifications mailing list