Check null value for given object to avoid possibly segfaulting

This commit is contained in:
Akira TAGOH 2012-03-07 17:56:39 +09:00
parent 1f01c4b60c
commit 0ca752dd25
1 changed files with 103 additions and 72 deletions

View File

@ -54,6 +54,8 @@ FcCharSetDestroy (FcCharSet *fcs)
{
int i;
if (fcs)
{
if (fcs->ref == FC_REF_CONSTANT)
{
FcCacheObjectDereference (fcs);
@ -77,6 +79,7 @@ FcCharSetDestroy (FcCharSet *fcs)
FcMemFree (FC_MEM_CHARSET, sizeof (FcCharSet));
free (fcs);
}
}
/*
* Search for the leaf containing with the specified num.
@ -252,7 +255,7 @@ FcCharSetAddChar (FcCharSet *fcs, FcChar32 ucs4)
FcCharLeaf *leaf;
FcChar32 *b;
if (fcs->ref == FC_REF_CONSTANT)
if (fcs == NULL || fcs->ref == FC_REF_CONSTANT)
return FcFalse;
leaf = FcCharSetFindLeafCreate (fcs, ucs4);
if (!leaf)
@ -268,7 +271,7 @@ FcCharSetDelChar (FcCharSet *fcs, FcChar32 ucs4)
FcCharLeaf *leaf;
FcChar32 *b;
if (fcs->ref == FC_REF_CONSTANT)
if (fcs == NULL || fcs->ref == FC_REF_CONSTANT)
return FcFalse;
leaf = FcCharSetFindLeaf (fcs, ucs4);
if (!leaf)
@ -341,11 +344,14 @@ FcCharSetIterStart (const FcCharSet *fcs, FcCharSetIter *iter)
FcCharSet *
FcCharSetCopy (FcCharSet *src)
{
if (src)
{
if (src->ref != FC_REF_CONSTANT)
src->ref++;
else
FcCacheObjectReference (src);
}
return src;
}
@ -357,6 +363,8 @@ FcCharSetEqual (const FcCharSet *a, const FcCharSet *b)
if (a == b)
return FcTrue;
if (!a || !b)
return FcFalse;
for (FcCharSetIterStart (a, &ai), FcCharSetIterStart (b, &bi);
ai.leaf && bi.leaf;
FcCharSetIterNext (a, &ai), FcCharSetIterNext (b, &bi))
@ -394,6 +402,8 @@ FcCharSetOperate (const FcCharSet *a,
FcCharSet *fcs;
FcCharSetIter ai, bi;
if (!a || !b)
goto bail0;
fcs = FcCharSetCreate ();
if (!fcs)
goto bail0;
@ -493,6 +503,9 @@ FcCharSetMerge (FcCharSet *a, const FcCharSet *b, FcBool *changed)
int ai = 0, bi = 0;
FcChar16 an, bn;
if (!a || !b)
return FcFalse;
if (a->ref == FC_REF_CONSTANT) {
if (changed)
*changed = FcFalse;
@ -561,7 +574,11 @@ FcCharSetSubtract (const FcCharSet *a, const FcCharSet *b)
FcBool
FcCharSetHasChar (const FcCharSet *fcs, FcChar32 ucs4)
{
FcCharLeaf *leaf = FcCharSetFindLeaf (fcs, ucs4);
FcCharLeaf *leaf;
if (!fcs)
return FcFalse;
leaf = FcCharSetFindLeaf (fcs, ucs4);
if (!leaf)
return FcFalse;
return (leaf->map[(ucs4 & 0xff) >> 5] & (1 << (ucs4 & 0x1f))) != 0;
@ -586,6 +603,8 @@ FcCharSetIntersectCount (const FcCharSet *a, const FcCharSet *b)
FcCharSetIter ai, bi;
FcChar32 count = 0;
if (a && b)
{
FcCharSetIterStart (a, &ai);
FcCharSetIterStart (b, &bi);
while (ai.leaf && bi.leaf)
@ -610,6 +629,7 @@ FcCharSetIntersectCount (const FcCharSet *a, const FcCharSet *b)
FcCharSetIterSet (b, &bi);
}
}
}
return count;
}
@ -619,6 +639,8 @@ FcCharSetCount (const FcCharSet *a)
FcCharSetIter ai;
FcChar32 count = 0;
if (a)
{
for (FcCharSetIterStart (a, &ai); ai.leaf; FcCharSetIterNext (a, &ai))
{
int i = 256/32;
@ -627,6 +649,7 @@ FcCharSetCount (const FcCharSet *a)
while (i--)
count += FcCharSetPopCount (*am++);
}
}
return count;
}
@ -636,6 +659,8 @@ FcCharSetSubtractCount (const FcCharSet *a, const FcCharSet *b)
FcCharSetIter ai, bi;
FcChar32 count = 0;
if (a && b)
{
FcCharSetIterStart (a, &ai);
FcCharSetIterStart (b, &bi);
while (ai.leaf)
@ -663,6 +688,7 @@ FcCharSetSubtractCount (const FcCharSet *a, const FcCharSet *b)
FcCharSetIterSet (b, &bi);
}
}
}
return count;
}
@ -675,7 +701,10 @@ FcCharSetIsSubset (const FcCharSet *a, const FcCharSet *b)
int ai, bi;
FcChar16 an, bn;
if (a == b) return FcTrue;
if (a == b)
return FcTrue;
if (!a || !b)
return FcFalse;
bi = 0;
ai = 0;
while (ai < a->num && bi < b->num)
@ -734,6 +763,8 @@ FcCharSetNextPage (const FcCharSet *a,
FcCharSetIter ai;
FcChar32 page;
if (!a)
return FC_CHARSET_DONE;
ai.ucs4 = *next;
FcCharSetIterSet (a, &ai);
if (!ai.leaf)