Commit ff699e64 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Check the OC we found exists before using it

Fixes crash http://bugs.freedesktop.org/show_bug.cgi?id=15899
parent ac26ba51
......@@ -162,12 +162,18 @@ OptionalContentGroup* OCGs::findOcgByRef( const Ref &ref)
{
//TODO: make this more efficient
OptionalContentGroup *ocg = NULL;
for (int i=0; i < optionalContentGroups->getLength(); ++i) {
ocg = (OptionalContentGroup*)optionalContentGroups->get(i);
if ( (ocg->ref().num == ref.num) && (ocg->ref().gen == ref.gen) ) {
return ocg;
if (optionalContentGroups != NULL)
{
for (int i=0; i < optionalContentGroups->getLength(); ++i) {
ocg = (OptionalContentGroup*)optionalContentGroups->get(i);
if ( (ocg->ref().num == ref.num) && (ocg->ref().gen == ref.gen) ) {
return ocg;
}
}
}
error(-1, "Could not find a OCG with Ref (%d:%d)", ref.num, ref.gen);
// not found
return NULL;
}
......@@ -208,7 +214,7 @@ bool OCGs::optContentIsVisible( Object *dictRef )
}
} else if (ocg.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocg.getRef() );
if ( oc->state() == OptionalContentGroup::Off ) {
if ( !oc || oc->state() == OptionalContentGroup::Off ) {
result = false;
} else {
result = true ;
......@@ -218,13 +224,10 @@ bool OCGs::optContentIsVisible( Object *dictRef )
policy.free();
} else if ( dictType.isName("OCG") ) {
OptionalContentGroup* oc = findOcgByRef( dictRef->getRef() );
if ( oc ) {
// printf("Found valid group object\n");
if ( oc->state() == OptionalContentGroup::Off ) {
result=false;
}
if ( !oc || oc->state() == OptionalContentGroup::Off ) {
result=false;
}
}
}
dictType.free();
dictObj.free();
// printf("visibility: %s\n", result? "on" : "off");
......@@ -238,7 +241,7 @@ bool OCGs::allOn( Array *ocgArray )
ocgArray->getNF(i, &ocgItem);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc->state() == OptionalContentGroup::Off ) {
if ( oc && oc->state() == OptionalContentGroup::Off ) {
return false;
}
}
......@@ -253,7 +256,7 @@ bool OCGs::allOff( Array *ocgArray )
ocgArray->getNF(i, &ocgItem);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc->state() == OptionalContentGroup::On ) {
if ( oc && oc->state() == OptionalContentGroup::On ) {
return false;
}
}
......@@ -268,7 +271,7 @@ bool OCGs::anyOn( Array *ocgArray )
ocgArray->getNF(i, &ocgItem);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc->state() == OptionalContentGroup::On ) {
if ( oc && oc->state() == OptionalContentGroup::On ) {
return true;
}
}
......@@ -283,7 +286,7 @@ bool OCGs::anyOff( Array *ocgArray )
ocgArray->getNF(i, &ocgItem);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc->state() == OptionalContentGroup::Off ) {
if ( oc && oc->state() == OptionalContentGroup::Off ) {
return true;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment