stream-restore,device-restore: Avoid unaligned access
authorArun Raghavan <arun@asymptotic.io>
Thu, 23 Jul 2020 23:42:47 +0000 (19:42 -0400)
committerArun Raghavan <arun@arunraghavan.net>
Mon, 23 Nov 2020 19:02:33 +0000 (19:02 +0000)
commit9055f5baf37e379d5e3b556bff1741565442723e
treeb51b550ef13fb98c0fcc87233e397830402a17d8
parentc442227c6bc64789cb4bd47dbd0b73b11e7a60e4
stream-restore,device-restore: Avoid unaligned access

Newer GCC warns us that the channel_map and volume in legacy entries are
accessed via pointers, and these might be unaligned as the legacy entry
is a packed structure. For this reason, we read out those values into
local variables before accessing them as pointers.

The warnings are:

[146/433] Compiling C object src/modules/module-device-restore.so.p/module-device-restore.c.o
../src/modules/module-device-restore.c: In function ‘legacy_entry_read’:
../src/modules/module-device-restore.c:554:51: warning: taking address of packed member of ‘struct legacy_entry’ may result in an unaligned pointer value [-Waddress-of-packed-member]
  554 |     if (le->volume_valid && !pa_channel_map_valid(&le->channel_map)) {
      |                                                   ^~~~~~~~~~~~~~~~
../src/modules/module-device-restore.c:559:48: warning: taking address of packed member of ‘struct legacy_entry’ may result in an unaligned pointer value [-Waddress-of-packed-member]
  559 |     if (le->volume_valid && (!pa_cvolume_valid(&le->volume) || !pa_cvolume_compatible_with_channel_map(&le->volume, &le->channel_map))) {
      |                                                ^~~~~~~~~~~
../src/modules/module-device-restore.c:559:104: warning: taking address of packed member of ‘struct legacy_entry’ may result in an unaligned pointer value [-Waddress-of-packed-member]
  559 |     if (le->volume_valid && (!pa_cvolume_valid(&le->volume) || !pa_cvolume_compatible_with_channel_map(&le->volume, &le->channel_map))) {
      |                                                                                                        ^~~~~~~~~~~
../src/modules/module-device-restore.c:559:117: warning: taking address of packed member of ‘struct legacy_entry’ may result in an unaligned pointer value [-Waddress-of-packed-member]
  559 |     if (le->volume_valid && (!pa_cvolume_valid(&le->volume) || !pa_cvolume_compatible_with_channel_map(&le->volume, &le->channel_map))) {
      |                                                                                                                     ^~~~~~~~~~~~~~~~
[211/433] Compiling C object src/modules/module-stream-restore.so.p/module-stream-restore.c.o
../src/modules/module-stream-restore.c: In function ‘legacy_entry_read’:
../src/modules/module-stream-restore.c:1076:51: warning: taking address of packed member of ‘struct legacy_entry’ may result in an unaligned pointer value [-Waddress-of-packed-member]
 1076 |     if (le->volume_valid && !pa_channel_map_valid(&le->channel_map)) {
      |                                                   ^~~~~~~~~~~~~~~~
../src/modules/module-stream-restore.c:1081:48: warning: taking address of packed member of ‘struct legacy_entry’ may result in an unaligned pointer value [-Waddress-of-packed-member]
 1081 |     if (le->volume_valid && (!pa_cvolume_valid(&le->volume) || !pa_cvolume_compatible_with_channel_map(&le->volume, &le->channel_map))) {
      |                                                ^~~~~~~~~~~
../src/modules/module-stream-restore.c:1081:104: warning: taking address of packed member of ‘struct legacy_entry’ may result in an unaligned pointer value [-Waddress-of-packed-member]
 1081 |     if (le->volume_valid && (!pa_cvolume_valid(&le->volume) || !pa_cvolume_compatible_with_channel_map(&le->volume, &le->channel_map))) {
      |                                                                                                        ^~~~~~~~~~~
../src/modules/module-stream-restore.c:1081:117: warning: taking address of packed member of ‘struct legacy_entry’ may result in an unaligned pointer value [-Waddress-of-packed-member]
 1081 |     if (le->volume_valid && (!pa_cvolume_valid(&le->volume) || !pa_cvolume_compatible_with_channel_map(&le->volume, &le->channel_map))) {
      |
src/modules/module-device-restore.c
src/modules/module-stream-restore.c