[rtems commit] capture: prevent unaligned access when reading time

Daniel Hellstrom danielh at rtems.org
Fri Aug 24 13:53:12 UTC 2018


Module:    rtems
Branch:    master
Commit:    0d51b6d87e3ad85b669fa11445fe71dbd6936e3d
Changeset: http://git.rtems.org/rtems/commit/?id=0d51b6d87e3ad85b669fa11445fe71dbd6936e3d

Author:    Daniel Hellstrom <daniel at gaisler.com>
Date:      Thu Jun 28 14:39:37 2018 +0200

capture: prevent unaligned access when reading time

LLVM warns about this:
 cpukit/libmisc/capture/capture.c:405:30: warning:
      taking address of packed member 'time' of class or structure
      'rtems_capture_record' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
    rtems_capture_get_time (&in.time);

And on sparc it generates an unaligned trap which makes smpcapture01
and smpcapture02 test to fail on sparc.

---

 cpukit/libmisc/capture/capture.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cpukit/libmisc/capture/capture.c b/cpukit/libmisc/capture/capture.c
index 19a90c5..4d40b8f 100644
--- a/cpukit/libmisc/capture/capture.c
+++ b/cpukit/libmisc/capture/capture.c
@@ -387,6 +387,7 @@ rtems_capture_record_open (rtems_tcb*                         tcb,
   if (ptr != NULL)
   {
     rtems_capture_record in;
+    rtems_capture_time time;
 
     ++cpu->count;
 
@@ -402,7 +403,8 @@ rtems_capture_record_open (rtems_tcb*                         tcb,
                   rtems_capture_task_real_priority (tcb) |
                   (rtems_capture_task_curr_priority (tcb) << 8));
 
-    rtems_capture_get_time (&in.time);
+    rtems_capture_get_time (&time);
+    in.time = time; /* need this since in is a packed struct */
 
     ptr = rtems_capture_record_append(ptr, &in, sizeof(in));
   }




More information about the vc mailing list