[i3] ipc.c: unaligned memory accesses on sparc

  • From: David Coppa <dcoppa@xxxxxxxxxxx>
  • To: i3-discuss@xxxxxxxxxxxxx
  • Date: Thu, 28 Apr 2011 02:13:11 -0600


Hi!

There's an unaligned memory accesses on sparc that makes i3 crash
when you run i3-wsbar or i3bar by Merovius.

Here's the backtrace:


GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "sparc64-unknown-openbsd4.9"...
(gdb) run
Starting program: /usr/local/bin/i3
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

...

Found binding mod9 with key 27 and command restart

Program received signal SIGBUS, Bus error.
ipc_receive_message (loop=Variable "loop" is not available.
) at src/ipc.c:440
440 uint32_t message_size = *((uint32_t*)message);
(gdb) bt
#0 ipc_receive_message (loop=Variable "loop" is not available.
) at src/ipc.c:440
#1 0x000000020c5ab6d8 in ev_invoke_pending () from /usr/local/lib/libev.so.2.1
#2 0x000000020c5b074c in ev_run () from /usr/local/lib/libev.so.2.1
#3 0x0000000000114b94 in main (argc=Variable "argc" is not available.
) at ev.h:810
(gdb) bt full
#0 ipc_receive_message (loop=Variable "loop" is not available.
) at src/ipc.c:440
message_size = Variable "message_size" is not available.
(gdb) quit
The program is running. Exit anyway? (y or n)


The following diff fixes the issue for me:


From: David Coppa <dcoppa@xxxxxxxxx>

---
src/ipc.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/ipc.c b/src/ipc.c
index b3052a2..8792868 100644
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -458,7 +458,8 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int
revents) {
n -= strlen(I3_IPC_MAGIC);

/* The next 32 bit after the magic are the message size */
- uint32_t message_size = *((uint32_t*)message);
+ uint32_t message_size;
+ memcpy(&message_size, (uint32_t*)message, sizeof(uint32_t));
message += sizeof(uint32_t);
n -= sizeof(uint32_t);

@@ -468,7 +469,8 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int
revents) {
}

/* The last 32 bits of the header are the message type */
- uint32_t message_type = *((uint32_t*)message);
+ uint32_t message_type;
+ memcpy(&message_type, (uint32_t*)message, sizeof(uint32_t));
message += sizeof(uint32_t);
n -= sizeof(uint32_t);


Other related posts: