mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
tweaks to keep static analyzer happy
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@36527 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d68d872655
commit
d26640c7ab
12 changed files with 158 additions and 118 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
2013-04-14 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Headers/GNUstepBase/GSIMap.h:
|
||||
* Headers/GNUstepBase/NSObject+GNUstepBase.h:
|
||||
* Source/Additions/GSObjCRuntime.m:
|
||||
* Source/GSFormat.m:
|
||||
* Source/GSPrivate.h:
|
||||
* Source/GSString.m:
|
||||
* Source/NSBundle.m:
|
||||
* Source/NSJSONSerialization.m:
|
||||
* Source/NSKeyValueObserving.m:
|
||||
* Source/NSScanner.m:
|
||||
* Tools/gdomap.c:
|
||||
Tweaks to keep static analyser happy.
|
||||
|
||||
2013-04-13 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Headers/GNUstepBase/GNUstep.h: NSInteger/NSUInteger cleanup.
|
||||
|
|
|
@ -484,10 +484,11 @@ GSIMapRemoveAndFreeNode(GSIMapTable map, uintptr_t bkt, GSIMapNode node)
|
|||
static INLINE void
|
||||
GSIMapRemoveWeak(GSIMapTable map)
|
||||
{
|
||||
uintptr_t bucketCount = map->bucketCount;
|
||||
GSIMapBucket bucket = map->buckets;
|
||||
if (GSI_MAP_ZEROED(map))
|
||||
{
|
||||
uintptr_t bucketCount = map->bucketCount;
|
||||
GSIMapBucket bucket = map->buckets;
|
||||
|
||||
while (bucketCount-- > 0)
|
||||
{
|
||||
GSIMapNode node = bucket->firstNode;
|
||||
|
@ -627,7 +628,8 @@ GSIMapNodeForKeyInBucket(GSIMapTable map, GSIMapBucket bucket, GSIMapKey key)
|
|||
|
||||
if (GSI_MAP_ZEROED(map))
|
||||
{
|
||||
while ((node != 0) && GSI_MAP_EQUAL(map, GSI_MAP_READ_KEY(map, &node->key), key) == NO)
|
||||
while ((node != 0)
|
||||
&& GSI_MAP_EQUAL(map, GSI_MAP_READ_KEY(map, &node->key), key) == NO)
|
||||
{
|
||||
GSIMapNode tmp = node->nextInBucket;
|
||||
|
||||
|
@ -640,7 +642,8 @@ GSIMapNodeForKeyInBucket(GSIMapTable map, GSIMapBucket bucket, GSIMapKey key)
|
|||
}
|
||||
return node;
|
||||
}
|
||||
while ((node != 0) && GSI_MAP_EQUAL(map, GSI_MAP_READ_KEY(map, &node->key), key) == NO)
|
||||
while ((node != 0)
|
||||
&& GSI_MAP_EQUAL(map, GSI_MAP_READ_KEY(map, &node->key), key) == NO)
|
||||
{
|
||||
node = node->nextInBucket;
|
||||
}
|
||||
|
@ -917,7 +920,8 @@ GSIMapEnumeratorNextNode(GSIMapEnumerator enumerator)
|
|||
|
||||
/* Find the frst available non-zeroed node.
|
||||
*/
|
||||
if (node != 0 && GSI_MAP_ZEROED(map) && GSI_MAP_READ_KEY(map, &node->key).addr == 0)
|
||||
if (node != 0 && GSI_MAP_ZEROED(map)
|
||||
&& GSI_MAP_READ_KEY(map, &node->key).addr == 0)
|
||||
{
|
||||
uintptr_t bucketCount = map->bucketCount;
|
||||
uintptr_t bucket = ((_GSIE)enumerator)->bucket;
|
||||
|
|
|
@ -144,7 +144,7 @@ extern "C" {
|
|||
* it is released during process exit if cleanup is enabled.<br />
|
||||
* Returns its argument.
|
||||
*/
|
||||
+ (id) leak: (id)anObject;
|
||||
+ (id) NS_RETURNS_RETAINED leak: (id)anObject;
|
||||
|
||||
/** This method retains the object at *anAddress so that it will never be
|
||||
* deallocated during normal operation, but keeps track of the address
|
||||
|
@ -152,7 +152,7 @@ extern "C" {
|
|||
* exit if cleanup is enabled.<br />
|
||||
* Returns the object at *anAddress.
|
||||
*/
|
||||
+ (id) leakAt: (id*)anAddress;
|
||||
+ (id) NS_RETURNS_RETAINED leakAt: (id*)anAddress;
|
||||
|
||||
/** Sets the receiver to have its +atExit method called at the point when
|
||||
* the process terminates.<br />
|
||||
|
|
|
@ -443,8 +443,6 @@ GSObjCMakeClass(NSString *name, NSString *superName, NSDictionary *iVars)
|
|||
Class newClass;
|
||||
Class classSuperClass;
|
||||
const char *classNameCString;
|
||||
char *tmp;
|
||||
int len;
|
||||
|
||||
NSCAssert(name, @"no name");
|
||||
NSCAssert(superName, @"no superName");
|
||||
|
@ -455,12 +453,6 @@ GSObjCMakeClass(NSString *name, NSString *superName, NSDictionary *iVars)
|
|||
NSCAssert1(!NSClassFromString(name), @"A class %@ already exists", name);
|
||||
|
||||
classNameCString = [name UTF8String];
|
||||
len = strlen(classNameCString);
|
||||
tmp = malloc(len + 1);
|
||||
strncpy(tmp, classNameCString, len);
|
||||
tmp[len] = '\0';
|
||||
classNameCString = tmp;
|
||||
|
||||
newClass = objc_allocateClassPair(classSuperClass, classNameCString, 0);
|
||||
if ([iVars count] > 0)
|
||||
{
|
||||
|
|
|
@ -1747,8 +1747,8 @@ NSDictionary *locale)
|
|||
{
|
||||
/* This is complicated. We have to transform the multibyte
|
||||
string into a unicode string. */
|
||||
const char *str = (const char*)string;
|
||||
unsigned blen;
|
||||
const char *str = (const char*)string;
|
||||
unsigned blen;
|
||||
static NSStringEncoding enc = GSUndefinedEncoding;
|
||||
static BOOL byteEncoding = NO;
|
||||
|
||||
|
@ -1799,8 +1799,8 @@ NSDictionary *locale)
|
|||
* enough for the unichar version.
|
||||
*/
|
||||
if (blen < 8192 || ((string = (unichar *)
|
||||
NSZoneMalloc(s->_zone, blen * sizeof(unichar))) == NULL))
|
||||
string = (unichar *) alloca (blen * sizeof(unichar));
|
||||
NSZoneMalloc(s->_zone, (blen + 1) * sizeof(unichar))) == NULL))
|
||||
string = (unichar *) alloca((blen + 1) * sizeof(unichar));
|
||||
else
|
||||
string_malloced = 1;
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ typedef struct objc_category* Category;
|
|||
* arrays are allocated on the stack (for speed), but large arrays are
|
||||
* allocated from the heap (to avoid stack overflow).
|
||||
*/
|
||||
#if __GNUC__ > 3
|
||||
#if __GNUC__ > 3 && !defined(__clang__)
|
||||
__attribute__((unused)) static void GSFreeTempBuffer(void **b)
|
||||
{
|
||||
if (NULL != *b) free(*b);
|
||||
|
@ -110,8 +110,10 @@ __attribute__((unused)) static void GSFreeTempBuffer(void **b)
|
|||
P = _base;\
|
||||
}
|
||||
#else
|
||||
/* Make minimum size of _ibuf 1 to avoid compiler warnings.
|
||||
*/
|
||||
# define GS_BEGINITEMBUF(P, S, T) { \
|
||||
T _ibuf[(S) <= GS_MAX_OBJECTS_FROM_STACK ? (S) : 0]; \
|
||||
T _ibuf[(S) > 0 && (S) <= GS_MAX_OBJECTS_FROM_STACK ? (S) : 1]; \
|
||||
T *_base = ((S) <= GS_MAX_OBJECTS_FROM_STACK) ? _ibuf \
|
||||
: (T*)NSZoneMalloc(NSDefaultMallocZone(), (S) * sizeof(T)); \
|
||||
T *(P) = _base;
|
||||
|
@ -122,7 +124,7 @@ __attribute__((unused)) static void GSFreeTempBuffer(void **b)
|
|||
* arrays of items. Use GS_BEGINITEMBUF() to start the block of code using
|
||||
* the array and this macro to end it.
|
||||
*/
|
||||
#if __GNUC__ > 3
|
||||
#if __GNUC__ > 3 && !defined(__clang__)
|
||||
# define GS_ENDITEMBUF() }
|
||||
#else
|
||||
# define GS_ENDITEMBUF() \
|
||||
|
|
|
@ -1035,8 +1035,14 @@ fixBOM(unsigned char **bytes, NSUInteger*length, BOOL *owned,
|
|||
}
|
||||
if (length > 0)
|
||||
{
|
||||
const void *original = bytes;
|
||||
const void *original;
|
||||
|
||||
if (0 == bytes)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"-initWithBytes:lenth:encoding given nul bytes"];
|
||||
}
|
||||
original = bytes;
|
||||
#if defined(OBJC_SMALL_OBJECT_SHIFT) && (OBJC_SMALL_OBJECT_SHIFT == 3)
|
||||
if (useTinyStrings)
|
||||
{
|
||||
|
@ -2632,11 +2638,11 @@ intValue_c(GSStr self)
|
|||
}
|
||||
else
|
||||
{
|
||||
unsigned len = (end - ptr) < 32 ? (end - ptr) : 31;
|
||||
char buf[len+1];
|
||||
unsigned int l = (end - ptr) < 32 ? (end - ptr) : 31;
|
||||
char buf[32];
|
||||
|
||||
memcpy(buf, ptr, len);
|
||||
buf[len] = '\0';
|
||||
memcpy(buf, ptr, l);
|
||||
buf[l] = '\0';
|
||||
return atol((const char*)buf);
|
||||
}
|
||||
}
|
||||
|
@ -2658,7 +2664,7 @@ intValue_u(GSStr self)
|
|||
else
|
||||
{
|
||||
unsigned int l = (end - ptr) < 32 ? (end - ptr) : 31;
|
||||
unsigned char buf[l+1];
|
||||
unsigned char buf[32];
|
||||
unsigned char *b = buf;
|
||||
|
||||
GSFromUnicode(&b, &l, ptr, l, internalEncoding, 0, GSUniTerminate);
|
||||
|
@ -4594,6 +4600,15 @@ NSAssert(_flags.owned == 1 && _zone != 0, NSInternalInconsistencyException);
|
|||
fixBOM((unsigned char**)&bytes, &length, &shouldFree, encoding);
|
||||
chars = (unsigned char*)bytes;
|
||||
}
|
||||
if (0 == length)
|
||||
{
|
||||
return [self initWithCapacity: 0];
|
||||
}
|
||||
if (0 == chars)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"-initWithBytes:lenth:encoding given nul bytes"];
|
||||
}
|
||||
|
||||
if (encoding == NSUTF8StringEncoding)
|
||||
{
|
||||
|
|
|
@ -2077,7 +2077,6 @@ IF_NO_GC(
|
|||
if (NSDecrementExtraRefCountWasZero(self))
|
||||
{
|
||||
[self dealloc];
|
||||
self = nil;
|
||||
}
|
||||
[load_lock unlock];
|
||||
}
|
||||
|
@ -2161,7 +2160,6 @@ IF_NO_GC(
|
|||
}
|
||||
if ([extension length] == 0)
|
||||
{
|
||||
extension = nil;
|
||||
file = name;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -561,7 +561,7 @@ parseObject(ParserState *state)
|
|||
c = consumeSpace(state);
|
||||
if (c == ',')
|
||||
{
|
||||
c = consumeChar(state);
|
||||
consumeChar(state);
|
||||
}
|
||||
c = consumeSpace(state);
|
||||
}
|
||||
|
|
|
@ -315,16 +315,26 @@ setup()
|
|||
static NSString *newKey(SEL _cmd)
|
||||
{
|
||||
const char *name = sel_getName(_cmd);
|
||||
unsigned len = strlen(name);
|
||||
unsigned len;
|
||||
NSString *key;
|
||||
unsigned i;
|
||||
NSCAssert(len > 0, @"Invalid selector name!");
|
||||
|
||||
if (0 == _cmd || 0 == (name = sel_getName(_cmd)))
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"Missing selector name"];
|
||||
}
|
||||
len = strlen(name);
|
||||
if (*name == '_')
|
||||
{
|
||||
name++;
|
||||
len--;
|
||||
}
|
||||
if (len < 5 || name[len-1] != ':' || strncmp(name, "set", 3) != 0)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"Invalid selector name"];
|
||||
}
|
||||
name += 3; // Step past 'set'
|
||||
len -= 4; // allow for 'set' and trailing ':'
|
||||
for (i = 0; i < len; i++)
|
||||
|
|
|
@ -1251,20 +1251,25 @@ GSScanDouble(unichar *buf, unsigned length, double *result)
|
|||
{
|
||||
pos++;
|
||||
}
|
||||
if (pos >= length)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
/* Check for sign */
|
||||
if (pos < length)
|
||||
switch (buf[pos])
|
||||
{
|
||||
switch (buf[pos])
|
||||
{
|
||||
case '+':
|
||||
pos++;
|
||||
break;
|
||||
case '-':
|
||||
negativeMantissa = YES;
|
||||
pos++;
|
||||
break;
|
||||
}
|
||||
case '+':
|
||||
pos++;
|
||||
break;
|
||||
case '-':
|
||||
negativeMantissa = YES;
|
||||
pos++;
|
||||
break;
|
||||
}
|
||||
if (pos >= length)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
/* Scan the mantissa ... at most 18 digits and a decimal point.
|
||||
|
@ -1280,16 +1285,15 @@ GSScanDouble(unichar *buf, unsigned length, double *result)
|
|||
}
|
||||
dotPos = mantissaLength;
|
||||
}
|
||||
mantissaLength++;
|
||||
else
|
||||
{
|
||||
mantissaLength++;
|
||||
}
|
||||
}
|
||||
if (dotPos < 0)
|
||||
{
|
||||
dotPos = mantissaLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
mantissaLength -= 1;
|
||||
}
|
||||
|
||||
if (0 == mantissaLength)
|
||||
{
|
||||
|
@ -1308,22 +1312,12 @@ GSScanDouble(unichar *buf, unsigned length, double *result)
|
|||
{
|
||||
c = *ptr;
|
||||
ptr += 1;
|
||||
if ('.' == c)
|
||||
{
|
||||
c = *ptr;
|
||||
ptr += 1;
|
||||
}
|
||||
hi = hi * 10 + (c - '0');
|
||||
}
|
||||
for (; mantissaLength > 0; mantissaLength -= 1)
|
||||
{
|
||||
c = *ptr;
|
||||
ptr += 1;
|
||||
if ('.' == c)
|
||||
{
|
||||
c = *ptr;
|
||||
ptr += 1;
|
||||
}
|
||||
lo = lo * 10 + (c - '0');
|
||||
}
|
||||
value = (1.0e9 * hi) + lo;
|
||||
|
|
128
Tools/gdomap.c
128
Tools/gdomap.c
|
@ -185,6 +185,8 @@ static struct in_addr class_b_mask;
|
|||
static unsigned long class_c_net;
|
||||
struct in_addr class_c_mask;
|
||||
|
||||
static char *local_hostname = 0;
|
||||
|
||||
/*
|
||||
* Predeclare some of the functions used.
|
||||
*/
|
||||
|
@ -921,16 +923,18 @@ prb_add(struct in_addr *p)
|
|||
* If we already have an entry for this address, remove it from the list
|
||||
* ready for re-insertion in the correct place.
|
||||
*/
|
||||
for (i = 0; i < prb_used; i++)
|
||||
i = prb_used;
|
||||
while (i-- > 0)
|
||||
{
|
||||
if (memcmp(&prb[i]->sin, p, IASIZE) == 0)
|
||||
{
|
||||
n = prb[i];
|
||||
for (i++; i < prb_used; i++)
|
||||
prb_used--;
|
||||
while (i++ < prb_used)
|
||||
{
|
||||
prb[i-1] = prb[i];
|
||||
}
|
||||
prb_used--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -938,9 +942,9 @@ prb_add(struct in_addr *p)
|
|||
* Create a new entry structure if necessary.
|
||||
* Set the current time in the structure, so we know when we last had contact.
|
||||
*/
|
||||
if (n == 0)
|
||||
if (0 == n)
|
||||
{
|
||||
n = (prb_type*)malloc(sizeof(prb_type));
|
||||
n = (prb_type*)calloc(sizeof(prb_type), 1);
|
||||
n->sin = *p;
|
||||
}
|
||||
n->when = time(0);
|
||||
|
@ -950,25 +954,21 @@ prb_add(struct in_addr *p)
|
|||
*/
|
||||
if (prb_used >= prb_size)
|
||||
{
|
||||
int size = (prb_size + 16) * sizeof(prb_type*);
|
||||
|
||||
if (prb_size)
|
||||
prb_size = prb_used + 16;
|
||||
if (prb)
|
||||
{
|
||||
prb = (prb_type**)realloc(prb, size);
|
||||
prb_size += 16;
|
||||
prb = (prb_type**)realloc(prb, prb_size * sizeof(prb_type*));
|
||||
}
|
||||
else
|
||||
{
|
||||
prb = (prb_type**)malloc(size);
|
||||
prb_size = 16;
|
||||
prb = (prb_type**)calloc(prb_size * sizeof(prb_type*), 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Append the new item at the end of the list.
|
||||
*/
|
||||
prb[prb_used] = n;
|
||||
prb_used++;
|
||||
prb[prb_used++] = n;
|
||||
}
|
||||
|
||||
|
||||
|
@ -979,20 +979,18 @@ prb_add(struct in_addr *p)
|
|||
static void
|
||||
prb_del(struct in_addr *p)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int i = prb_used;
|
||||
|
||||
for (i = 0; i < prb_used; i++)
|
||||
while (i-- > 0)
|
||||
{
|
||||
if (memcmp(&prb[i]->sin, p, IASIZE) == 0)
|
||||
{
|
||||
unsigned int j;
|
||||
|
||||
free(prb[i]);
|
||||
for (j = i + 1; j < prb_used; j++)
|
||||
{
|
||||
prb[j-1] = prb[j];
|
||||
}
|
||||
prb_used--;
|
||||
while (i++ < prb_used)
|
||||
{
|
||||
prb[i - 1] = prb[i];
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1005,10 +1003,10 @@ prb_del(struct in_addr *p)
|
|||
static void
|
||||
prb_tim(time_t when)
|
||||
{
|
||||
int i;
|
||||
int i = prb_used;
|
||||
|
||||
when -= 1800;
|
||||
for (i = prb_used - 1; i >= 0; i--)
|
||||
while (i-- > 0)
|
||||
{
|
||||
if (noprobe == 0 && prb[i]->when < when && prb[i]->when < last_probe)
|
||||
{
|
||||
|
@ -1330,7 +1328,7 @@ init_iface()
|
|||
if (addr != 0) free(addr);
|
||||
addr = (struct in_addr*)malloc((MAX_IFACE+1)*IASIZE);
|
||||
if (bcok != 0) free(bcok);
|
||||
bcok = (unsigned char*)malloc((MAX_IFACE+1)*sizeof(char));
|
||||
bcok = (unsigned char*)malloc((MAX_IFACE+1)*sizeof(unsigned char));
|
||||
if (bcst != 0) free(bcst);
|
||||
bcst = (struct in_addr*)malloc((MAX_IFACE+1)*IASIZE);
|
||||
if (mask != 0) free(mask);
|
||||
|
@ -1563,7 +1561,7 @@ load_iface(const char* from)
|
|||
num_iface++;
|
||||
addr = (struct in_addr*)malloc((num_iface+1)*IASIZE);
|
||||
mask = (struct in_addr*)malloc((num_iface+1)*IASIZE);
|
||||
bcok = (unsigned char*)malloc((num_iface+1)*sizeof(char));
|
||||
bcok = (unsigned char*)malloc((num_iface+1)*sizeof(unsigned char));
|
||||
bcst = (struct in_addr*)malloc((num_iface+1)*IASIZE);
|
||||
|
||||
addr[interfaces].s_addr = inet_addr("127.0.0.1");
|
||||
|
@ -2234,7 +2232,7 @@ init_probe()
|
|||
}
|
||||
if (indirect)
|
||||
{
|
||||
struct in_addr *other;
|
||||
struct in_addr *other = 0;
|
||||
int elen;
|
||||
|
||||
/*
|
||||
|
@ -2261,7 +2259,7 @@ init_probe()
|
|||
queue_probe(&p->addr, addr, len, other, 0);
|
||||
}
|
||||
}
|
||||
if (elen > 0)
|
||||
if (0 != other)
|
||||
{
|
||||
free(other);
|
||||
}
|
||||
|
@ -2677,6 +2675,12 @@ handle_request(int desc)
|
|||
map_ent *m;
|
||||
|
||||
ri = getRInfo(desc, 0);
|
||||
if (0 == ri)
|
||||
{
|
||||
snprintf(ebuf, sizeof(ebuf), "request not found on descriptor %d", desc);
|
||||
gdomap_log(LOG_DEBUG);
|
||||
return;
|
||||
}
|
||||
type = ri->buf.r.rtype;
|
||||
size = ri->buf.r.nsize;
|
||||
ptype = ri->buf.r.ptype;
|
||||
|
@ -3056,8 +3060,8 @@ handle_request(int desc)
|
|||
unsigned int j;
|
||||
|
||||
free(wi->buf);
|
||||
wi->buf = (char*)malloc(sizeof(unsigned long)
|
||||
+ (prb_used+1)*IASIZE);
|
||||
wi->buf = (char*)calloc(sizeof(unsigned long)
|
||||
+ (prb_used+1)*IASIZE, 1);
|
||||
*(unsigned long*)wi->buf = htonl(prb_used+1);
|
||||
memcpy(&wi->buf[4], &ri->addr.sin_addr, IASIZE);
|
||||
|
||||
|
@ -3176,7 +3180,7 @@ handle_request(int desc)
|
|||
{
|
||||
struct in_addr laddr;
|
||||
struct in_addr raddr;
|
||||
struct in_addr *other;
|
||||
struct in_addr *other = 0;
|
||||
unsigned int elen;
|
||||
void *rbuf = ri->buf.r.name;
|
||||
void *wbuf;
|
||||
|
@ -3184,8 +3188,8 @@ handle_request(int desc)
|
|||
gdo_req *r;
|
||||
|
||||
free(wi->buf);
|
||||
wi->buf = (char*)calloc(GDO_REQ_SIZE,1);
|
||||
r = (gdo_req*)wi->buf;
|
||||
r = (gdo_req*)calloc(GDO_REQ_SIZE, 1);
|
||||
wi->buf = (char*)r;
|
||||
wbuf = r->name;
|
||||
r->rtype = GDO_PREPLY;
|
||||
r->nsize = IASIZE*2;
|
||||
|
@ -3240,6 +3244,10 @@ handle_request(int desc)
|
|||
}
|
||||
queue_probe(&raddr, &laddr, elen, other, 1);
|
||||
}
|
||||
if (0 != other)
|
||||
{
|
||||
free(other);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -3769,7 +3777,10 @@ int ptype, struct sockaddr_in* addr, unsigned short* p, uptr*v)
|
|||
port = 0;
|
||||
}
|
||||
msg.port = htonl(port);
|
||||
memcpy(msg.name, name, len);
|
||||
if (name && len)
|
||||
{
|
||||
memcpy(msg.name, name, len);
|
||||
}
|
||||
|
||||
e = tryWrite(desc, 10, (uptr)&msg, GDO_REQ_SIZE);
|
||||
if (e != GDO_REQ_SIZE)
|
||||
|
@ -3867,7 +3878,10 @@ int ptype, struct sockaddr_in* addr, unsigned short* p, uptr*v)
|
|||
gdomap_log(LOG_ERR);
|
||||
port = 0;
|
||||
}
|
||||
*v = b;
|
||||
if (0 != v)
|
||||
{
|
||||
*v = b;
|
||||
}
|
||||
}
|
||||
|
||||
*p = (unsigned short)port;
|
||||
|
@ -3928,14 +3942,13 @@ nameServer(const char* name, const char* host, int op, int ptype, struct sockadd
|
|||
{
|
||||
struct sockaddr_in sin;
|
||||
struct hostent* hp;
|
||||
unsigned short p = htons(GDOMAP_PORT);
|
||||
unsigned short p;
|
||||
unsigned short port = 0;
|
||||
int len = strlen(name);
|
||||
int multi = 0;
|
||||
int found = 0;
|
||||
int rval;
|
||||
char *first_dot = 0;
|
||||
char *local_hostname = 0;
|
||||
|
||||
if (len == 0)
|
||||
{
|
||||
|
@ -3963,6 +3976,10 @@ nameServer(const char* name, const char* host, int op, int ptype, struct sockadd
|
|||
{
|
||||
p = sp->s_port; /* Network byte order. */
|
||||
}
|
||||
else
|
||||
{
|
||||
p = htons(GDOMAP_PORT);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -3979,14 +3996,6 @@ nameServer(const char* name, const char* host, int op, int ptype, struct sockadd
|
|||
*/
|
||||
if (multi || host == 0 || *host == '\0')
|
||||
{
|
||||
local_hostname = xgethostname();
|
||||
if (!local_hostname)
|
||||
{
|
||||
snprintf(ebuf, sizeof(ebuf),
|
||||
"gethostname() failed: %s", strerror(errno));
|
||||
gdomap_log(LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
first_dot = strchr(local_hostname, '.');
|
||||
if (first_dot)
|
||||
{
|
||||
|
@ -4093,7 +4102,7 @@ nameServer(const char* name, const char* host, int op, int ptype, struct sockadd
|
|||
}
|
||||
}
|
||||
rval = tryHost(op, len, (unsigned char*)name, ptype, &sin, &port, 0);
|
||||
if (rval != 0 && host == local_hostname)
|
||||
if (rval != 0)
|
||||
{
|
||||
snprintf(ebuf, sizeof(ebuf),
|
||||
"failed to contact gdomap on %s(%s) - %s",
|
||||
|
@ -4122,7 +4131,6 @@ nameServer(const char* name, const char* host, int op, int ptype, struct sockadd
|
|||
memcpy(&addr->sin_addr, &sin.sin_addr, sizeof(sin.sin_addr));
|
||||
addr->sin_family = AF_INET;
|
||||
addr->sin_port = htons(port);
|
||||
free(local_hostname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -4152,12 +4160,11 @@ donames(const char *host)
|
|||
{
|
||||
struct sockaddr_in sin;
|
||||
struct hostent* hp;
|
||||
unsigned short p = htons(GDOMAP_PORT);
|
||||
unsigned short p;
|
||||
unsigned short num = 0;
|
||||
int rval;
|
||||
uptr b;
|
||||
char *first_dot = 0;
|
||||
char *local_hostname = NULL;
|
||||
|
||||
#if GDOMAP_PORT_OVERRIDE
|
||||
p = htons(GDOMAP_PORT_OVERRIDE);
|
||||
|
@ -4172,6 +4179,10 @@ donames(const char *host)
|
|||
{
|
||||
p = sp->s_port; /* Network byte order. */
|
||||
}
|
||||
else
|
||||
{
|
||||
p = htons(GDOMAP_PORT);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -4180,15 +4191,6 @@ donames(const char *host)
|
|||
/*
|
||||
* If no host name is given, we use the name of the local host.
|
||||
*/
|
||||
|
||||
local_hostname = xgethostname();
|
||||
if (!local_hostname)
|
||||
{
|
||||
snprintf(ebuf, sizeof(ebuf),
|
||||
"gethostname() failed: %s", strerror(errno));
|
||||
gdomap_log(LOG_ERR);
|
||||
return;
|
||||
}
|
||||
first_dot = strchr(local_hostname, '.');
|
||||
if (first_dot)
|
||||
{
|
||||
|
@ -4252,7 +4254,6 @@ donames(const char *host)
|
|||
}
|
||||
}
|
||||
free(b);
|
||||
free(local_hostname);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -4467,6 +4468,15 @@ main(int argc, char** argv)
|
|||
WSAStartup(wVersionRequested, &wsaData);
|
||||
#endif
|
||||
|
||||
local_hostname = xgethostname();
|
||||
if (!local_hostname)
|
||||
{
|
||||
snprintf(ebuf, sizeof(ebuf),
|
||||
"gethostname() failed: %s", strerror(errno));
|
||||
gdomap_log(LOG_CRIT);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Would use inet_aton(), but older systems don't have it.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue