Description
Hi,
When accessing remote data, my program hits Segmentation fault. I've debug the issue and make sure that the cause is using "if (n<0)" to judge the getaddrinfo errors. In fact we should use "if (n!=0)" according to getaddrinfo() standard.
In the file: xercesc/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp, line 127:
int n = getaddrinfo(hostNameAsCharStar,portBuffer.getRawBuffer(),&hints, &res);
if(n<0)
http://linux.die.net/man/3/getaddrinfo point out that "getaddrinfo(3) returns 0 if it succeeds, or one of the following non-zero error codes". So the error code is not negative in all platform.
I've wrote a test program and run in both Linux and FreeBSD. The result show that the error codes on FreeBSD are positive number:
Linux:
error in getaddrinfo: Name or service not known
error code: -2
FreeBSD:
error in getaddrinfo: hostname nor servname provided, or not known
error code: 8
So the fix should be changing upon two "if(n<0)" into "if(n!=0)". The fix works on my machine.
Thanks,
Rucong