[rtems commit] capture: Fix unaligned pointer value warning

Sebastian Huber sebh at rtems.org
Sat Oct 10 13:16:00 UTC 2020


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

Author:    Frank Kühndel <frank.kuehndel at embedded-brains.de>
Date:      Mon Oct  5 16:20:44 2020 +0200

capture: Fix unaligned pointer value warning

rtems_name is a four byte integer.
Giving an rtems_name as value instead of a pointer to ctrace_task_name_add()
fixes not only the compiler warning but it is also a bit more safe

For those who have asked for the warning:

../../../cpukit/libmisc/capture/capture_support.c:352:49: warning:
taking address of packed member of 'struct rtems_capture_task_record'
may result in an unaligned pointer value [-Waddress-of-packed-member]
  352 |         ctrace_task_name_add (rec_out->task_id, &task_rec.name);
      |                                                 ^~~~~~~~~~~~~~

---

 cpukit/libmisc/capture/capture_support.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/cpukit/libmisc/capture/capture_support.c b/cpukit/libmisc/capture/capture_support.c
index 4af8822..e2438fb 100644
--- a/cpukit/libmisc/capture/capture_support.c
+++ b/cpukit/libmisc/capture/capture_support.c
@@ -81,7 +81,7 @@ static ctrace_tasks tasks;
  * Add a name.
  */
 static void
-ctrace_task_name_add (rtems_id id, const rtems_name* name)
+ctrace_task_name_add (rtems_id id, const rtems_name name)
 {
   if (tasks.tasks == NULL)
   {
@@ -97,7 +97,7 @@ ctrace_task_name_add (rtems_id id, const rtems_name* name)
       {
         if (tasks.tasks[t].id == id)
         {
-          tasks.tasks[t].name = *name;
+          tasks.tasks[t].name = name;
           break;
         }
       }
@@ -111,7 +111,7 @@ ctrace_task_name_add (rtems_id id, const rtems_name* name)
         }
         if (tasks.tasks != NULL)
         {
-          tasks.tasks[tasks.count].name = *name;
+          tasks.tasks[tasks.count].name = name;
           tasks.tasks[tasks.count].id = id;
           ++tasks.count;
         }
@@ -349,7 +349,7 @@ rtems_capture_print_trace_records (int total, bool csv)
         cpu->recs = rtems_capture_record_extract (cpu->recs,
                                                   &task_rec,
                                                   sizeof (task_rec));
-        ctrace_task_name_add (rec_out->task_id, &task_rec.name);
+        ctrace_task_name_add (rec_out->task_id, task_rec.name);
         rtems_capture_print_record_task (cpu_out, rec_out, &task_rec);
       }
       else



More information about the vc mailing list