dlundquist/sniproxy — pull request #133 by ChrisLundquist (2014-11-01 03:56:27+00:00)
Title: Fix tests (almost)

I was seeing occasional segfaults when running address_test.
It looks like it happened depending where things got allocated and we had an off by one error.
I'm not really that familiar with the code, but you had a nice function for finding address length, so I figured it would be good to use that.

```
(lldb) thread backtrace
* thread #1: tid = 0x722e2e, 0x00007fff95867db0 libsystem_platform.dylib`_platform_memcmp + 208, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x100500000)
* frame #0: 0x00007fff95867db0 libsystem_platform.dylib`_platform_memcmp + 208
frame #1: 0x0000000100002bd8 address_test`address_compare(addr_1=0x0000000100400000, addr_2=0x0000000100400000) + 296 at address.c:226
frame #2: 0x0000000100000aaf address_test`main + 207 at address_test.c:73
frame #3: 0x00007fff873885c9 libdyld.dylib`start + 1
frame #4: 0x00007fff873885c9 libdyld.dylib`start + 1

(lldb) process status
Process 59055 stopped
* thread #1: tid = 0x722e2e, 0x00007fff95867db0 libsystem_platform.dylib`_platform_memcmp + 208, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x100500000)
frame #0: 0x00007fff95867db0 libsystem_platform.dylib`_platform_memcmp + 208
libsystem_platform.dylib`_platform_memcmp + 208:
-> 0x7fff95867db0: movdqa (%rdi,%rcx), %xmm0
0x7fff95867db5: movdqu (%rsi,%rcx), %xmm1
0x7fff95867dba: pcmpeqb %xmm1, %xmm0
0x7fff95867dbe: pmovmskb %xmm0, %eax

(lldb) print (char*)addr_2->data;
(char *) $4 = 0x0000000100400012 "localhost"
(lldb) print (char*)addr_1->data;
(char *) $5 = 0x0000000100400012 "localhost"
```

With this patch we now consistently fail with:

```
$ tests/address_test
Assertion failed: (compare_address_strings("127.0.0.1", "127.0.0.1") == 0), function main, file address_test.c, line 140.
Abort trap: 6
```
I'm not entirely sure why, but this means we aren't segfaulting like we were on the previous tests.