代码复制有风险

程序原来支持IPv4,现在要支持IPv6,只有IP地址转换部分有区别,因此偷懒(时间也的确紧。。。)直接复制了原来代码修改,结果连续踩坑,v6好了,v4不能用了。。。

[DEBUG] &pgl:0x7ffef31e3868
[DEBUG] pgl:0x100a1a0 tid:0 rid:0 q:0x7ffef31e57c0 header:0x7fff7820262a msg:0x7ffef31e6110 rbuff:0x100e258 rbuff_len:0x7ffef31e5334 t:1489484783
[DEBUG] pgl->pgl:0x7ffe58df0010
[DEBUG]&(pgl->pgl->sp_lock):0x7ffe597fa0d8
[DEBUG] &pgl:0x7ffef31e3868
[DEBUG] &pgl:0x7ffef31e3868
[DEBUG] pgl:0x100a1a0 tid:0 rid:0 q:0x7ffef31e57c0 header:0x7fff7820262a msg:0x7ffef31e6110 rbuff:0x100e258 rbuff_len:0x7ffef31e5334 t:1489484783
[DEBUG] pgl->pgl:0x7ffe58df0010
[DEBUG]&(pgl->pgl->sp_lock):0x7ffe597fa0d8
[DEBUG]pthread_rwlock_unlock pgl:0x100a1a0
[DEBUG]pthread_rwlock_unlock pgl->pgl:0x7ffe58df0010
[DEBUG]pthread_rwlock_unlock &(pgl->pgl->sp_lock):0x7ffe597fa0d8
[DEBUG] &pgl:0x7ffef31e3868
[DEBUG] pgl:0x100a1a0 tid:0 rid:0 q:0x7ffef31e57c0 header:0x7fff782013aa msg:0x7ffef31e6110 rbuff:0x100e258 rbuff_len:0x7ffef31e5334 t:1489484783
[DEBUG] pgl->pgl:0x7ffe58df0010
[DEBUG]&(pgl->pgl->sp_lock):0x7ffe597fa0d8
[DEBUG] &pgl:0x7ffef31e3868
[DEBUG] &pgl:0x7ffef31e3868
[DEBUG] pgl:0x100a1a0 tid:0 rid:0 q:0x7ffef31e57c0 header:0x7fff782013aa msg:0x7ffef31e6110 rbuff:0x100e258 rbuff_len:0x7ffef31e5334 t:1489484783
[DEBUG] pgl->pgl:0x7ffe58df0010
[DEBUG]&(pgl->pgl->sp_lock):0x7ffe597fa0d8
[DEBUG]pthread_rwlock_unlock pgl:0x100a1a0
[DEBUG]pthread_rwlock_unlock pgl->pgl:0x7ffe58df0010
[DEBUG]pthread_rwlock_unlock &(pgl->pgl->sp_lock):0x7ffe597fa0d8
[DEBUG] &pgl:0x7ffef31e3868
[DEBUG] pgl:0x100a1a0 tid:0 rid:0 q:0x7ffef31e57c0 header:0x7fff78200a6a msg:0x7ffef31e6110 rbuff:0x100e258 rbuff_len:0x7ffef31e5334 t:1489484783
[DEBUG] pgl->pgl:0x7ffe58df0010
[DEBUG]&(pgl->pgl->sp_lock):0x7ffe597fa0d8
[DEBUG] &pgl:0x7ffef31e3868
[DEBUG] &pgl:0x653666363a2ebe

Program received signal SIGBUS, Bus error.
[Switching to Thread 0x7ffef31e7700 (LWP 38714)]
dns_f2c_process (pgl=, 
    pgl@entry=, 
    tid=, 
    tid@entry=, 
    rid=, 
    rid@entry=, 
    q=, 
    q@entry=, 
    header=, 
    header@entry=, 
    msg=, 
    msg@entry=, 
    rbuff=, 
    rbuff@entry=, 
    rbuff_len=, 
    rbuff_len@entry=, 
    t=, 
    t@entry=) at plug_dns_process.c:780
780		printf("[DEBUG] pgl:%p tid:%d rid:%d q:%p header:%p msg:%p rbuff:%p rbuff_len:%p t:%d\n",pgl, tid, rid, q, header, msg, rbuff, rbuff_len, t);
Missing separate debuginfos, use: debuginfo-install glibc-2.17-105.el7.x86_64
折腾了一天,通过笨方法,printf,夹逼到问题代码段,一眼就看出了问题

v4中原来是sp_value =(char*)inet_ntop(AF_INET,value,ip,48);

v6中是sp_value =(char*)inet_ntop(AF_INET6,value,ip,48);

结果修改v6的时候把v4也改成sp_value =(char*)inet_ntop(AF_INET6,value,ip,48);了


你可能感兴趣的:(c,段错误)