a few checks for failed mem allocation

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@36882 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2013-07-13 11:02:30 +00:00
parent 0608dda15b
commit e6e7cf4679
2 changed files with 24 additions and 9 deletions

View file

@ -5223,13 +5223,13 @@ static NSFileManager *fm = nil;
if (string == nil)
[NSException raise: NSInvalidArgumentException format: @"compare with nil"];
#if GS_USE_ICU == 1
if (nil != locale
&& ![locale isKindOfClass: [NSLocale class]])
&& ![locale isKindOfClass: [NSLocale class]])
{
locale = [NSLocale currentLocale];
}
#if GS_USE_ICU == 1
{
UCollator *coll = GSICUCollatorOpen(mask, locale);

View file

@ -712,28 +712,43 @@ compare(uptr n0, int l0, uptr n1, int l1)
static map_ent*
map_add(uptr n, unsigned char l, unsigned int p, unsigned char t)
{
map_ent *m = (map_ent*)malloc(sizeof(map_ent));
map_ent *m;
int i;
m = (map_ent*)malloc(sizeof(map_ent));
if (0 == m)
{
perror("no memory for map entry");
exit(EXIT_FAILURE);
}
m->port = p;
m->name = (unsigned char*)malloc(l);
if (0 == m->name)
{
perror("no memory for map entry name");
exit(EXIT_FAILURE);
}
m->size = l;
m->net = (t & GDO_NET_MASK);
m->svc = (t & GDO_SVC_MASK);
memcpy(m->name, n, l);
if (map_used >= map_size)
if (map_used == map_size)
{
if (map_size)
map_size += 16;
if (map)
{
map = (map_ent**)realloc(map, (map_size + 16)*sizeof(map_ent*));
map_size += 16;
map = (map_ent**)realloc(map, map_size * sizeof(map_ent*));
}
else
{
map = (map_ent**)calloc(16,sizeof(map_ent*));
map_size = 16;
map = (map_ent**)calloc(map_size, sizeof(map_ent*));
}
if (0 == map)
{
perror("no memory for map");
exit(EXIT_FAILURE);
}
}
for (i = 0; i < map_used; i++)
{