[lldb-dev] unaligned cast in TCPSocket::Connect

Greg Clayton via lldb-dev lldb-dev at lists.llvm.org
Mon Oct 17 09:01:22 PDT 2016


> On Oct 13, 2016, at 10:52 AM, Ted Woodward via lldb-dev <lldb-dev at lists.llvm.org> wrote:
> 
> TCPSocket::Connect has this line:
>             host_str = ::inet_ntoa (*(struct in_addr *)*host_entry->h_addr_list);
>  
> host_entry->h_addr_list is a char**, while struct in_addr contains a uint32_t. Casting like this (char * to uint_32t *) could cause a bus error on systems that don’t allow non-aligned loads. I think we need to memcpy the data into a struct in_addr variable.
>  
> Anyone have any thoughts on this?

You will have to memcpy into a local that will be correctly aligned before you play with it. Or you can use DataExtractor as it already does the right thing. We ran into similar issues with DWARF parsing on systems that don't allow non-aligned loads, so DataExtractor can extract data correctly no matter what the alignment.

Greg



More information about the lldb-dev mailing list