Hi,
I am getting an EXC BAD ACCESS Error when my c++ (I am using XCode) runs with certain files. The program extracts the annotations and highlights from a pdf file and is based on the poppler library. Now I am getting an EXC BAD ACCESS Error when I am working with files created with a certain PDF Viewer (files from other viewers work fine). Below is the (reduced) main function. The error occurs when I use the variable 'text' in the line:
When I exclude the variable everything works. Breakpoints suggest that the variable has been optimized away by compiler even though it's used in the line above.
I am getting an EXC BAD ACCESS Error when my c++ (I am using XCode) runs with certain files. The program extracts the annotations and highlights from a pdf file and is based on the poppler library. Now I am getting an EXC BAD ACCESS Error when I am working with files created with a certain PDF Viewer (files from other viewers work fine). Below is the (reduced) main function. The error occurs when I use the variable 'text' in the line:
Code:
outputString=std::string(fileName->getCString())+opS+text+"\n";
Code:
GooString *getContents() const { return contents; }
char *getCString() const { return s; }
Code:
int main(int argc, char *argv[]) {
PDFDoc *doc;
GooString *fileName;
GBool outputToFile= gFalse;
std::ofstream outputFile;
std::string outputString("");
std::string opS(" ; ");
Object info;
char *text;
// read config file
globalParams = new GlobalParams();
// get filename
fileName = new GooString(argv[1]);
// get pdf document
doc = PDFDocFactory().createPDFDoc(*fileName, NULL, NULL);
// iterate through pages
for (int page = 1; page <= doc->getNumPages(); ++page) {
// get current page
Page *currentPage= doc->getPage(page);
// get annotations
Annots *annots=currentPage->getAnnots(doc->getCatalog());
// number of attachments
int n_annots=annots->getNumAnnots();
// iterate through annotations
for (int a = 0; a < n_annots; ++a) {
// get annotation
Annot *annot=annots->getAnnot(a);
// get content of annotation
text=annot->getContents()->getCString();
// create output line
outputString=std::string(fileName->getCString())+opS+text+"\n";
// output annotation information
printf("%s", outputString.c_str());
}
}
return 0;
}
Last edited: