Re: [Podofo-users] Getting Segmentation fault when trying to access PdfVecObjects

2018-05-15 Thread Matthew Brincke
Hello Georg, hello all,
> On 10 May 2018 at 19:28 Georg Funk  wrote:
> 
> 
> Hi Joerg,
> 
> thanks for this hint.
> 
> I thought maybe I'm misusing PdfObject::Reference() and
> PdfObject::GetReference() in my code This could explain the null
> pointer.
> 
that could also be a problem, however GetObject() returning NULL should
mean that no object with the reference numbers given to the method was
found in the PdfDocument or PdfVecObjects your PdfObject belongs to,
so please check if this is the case (no such object exists). Only if it 
isn't, you could have found a bug in PoDoFo.

> I want to get an object's Reference number by calling
> PdfObject::Reference() and get a pointer to a eventually existing
> indirect object by calling PdfObject::GetReference().
> 
> Is this the correct use case?
> 

Only the former is correct, whereas PdfObject::GetReference() is
inherited from PdfVariant and throws a PdfError exception if
IsReference() returns false, so it is only for "converting"
(de-capsulating) a reference in PdfObject form to PdfReference
(returns a C++ reference to a PdfReference object, no pointer).
 
> Thanks in advance!
> 
> Georg 
> 
> 

Hope this helps.

Best regards, mabri

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users


Re: [Podofo-users] Getting Segmentation fault when trying to access PdfVecObjects

2018-05-10 Thread Georg Funk
Hi, Matthew,

Am Donnerstag, den 10.05.2018, 18:26 +0200 schrieb Matthew Brincke:
> [typos fixed and code re-wrapped in quote]
> 
> Hello Georg, hello all,
> > On 10 May 2018 at 16:14 Georg Funk  wrote:
> > 
> > 
> > Dear developers,
> > 
> > I'm getting a segmentation fault in the following code snippet when
> > resolving IsReference()):
> > 
> > if (objectVector.GetObject(currentReference)->IsReference()) {
> > currentReference = objectVector
> >  .GetObject(currentReference)->GetReference();
> > }
> > else {}
> > 
> > objectVector is a global variable here and currentReference holds a
> > PdfReference to look up.
> 
> the method PdfVecObjects::GetObject() (your objectVector is of type
> PdfVecObjects, right?) can return NULL (nullptr from C++11), this
> means that the the reference passed (your currentReference) could
> not be resolved (no object with those numbers was found in the
> vector).
> Then IsReference() would be called with NULL this (undefined
> behaviour
> AFAIK).
> 

Right, the objectVector is of the type PdfVecObjects.
I try to pass the content object of each page to my data model, which
has also function above, to build up a recursive Object-Tree.
But it fails at the very first invocation.

Georg
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users


Re: [Podofo-users] Getting Segmentation fault when trying to access PdfVecObjects

2018-05-10 Thread Matthew Brincke
[typos fixed and code re-wrapped in quote]

Hello Georg, hello all,
> On 10 May 2018 at 16:14 Georg Funk  wrote:
> 
> 
> Dear developers,
> 
> I'm getting a segmentation fault in the following code snippet when
> resolving IsReference()):
> 
> if (objectVector.GetObject(currentReference)->IsReference()) {
> currentReference = objectVector
>  .GetObject(currentReference)->GetReference();
> }
> else {}
> 
> objectVector is a global variable here and currentReference holds a
> PdfReference to look up.

the method PdfVecObjects::GetObject() (your objectVector is of type
PdfVecObjects, right?) can return NULL (nullptr from C++11), this
means that the the reference passed (your currentReference) could
not be resolved (no object with those numbers was found in the vector).
Then IsReference() would be called with NULL this (undefined behaviour
AFAIK).

> 
> Error message from gdb:
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x55ba2342486e in PoDoFo::PdfVariant::DelayedLoad (this=0x0) at
> /usr/local/include/podofo/base/PdfVariant.h:545
> 545   if( !m_bDelayedLoadDone)
> 

There it is, the "this" implicit argument with NULL value,
through some extra call(s).
> Have you any idea for me?

The return value of PdfVecObjects::GetObject() should be 
stored in a pointer variable which is then checked for
NULL (nullptr preferably for C++11 or newer) and used only
if it isn't equal to that.
> 
> Thank you!
> 

You're welcome.
> Best regards,
> Georg

Best regards, mabri

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users