From 6c994aa888cbc794002e876cc8ebe85eebdfe463 Mon Sep 17 00:00:00 2001 From: kramm Date: Mon, 6 Oct 2008 12:56:56 +0000 Subject: [PATCH] fixed memory violation in preparePage() --- lib/pdf/GFXOutputDev.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/pdf/GFXOutputDev.cc b/lib/pdf/GFXOutputDev.cc index f2074b8..16e5e91 100644 --- a/lib/pdf/GFXOutputDev.cc +++ b/lib/pdf/GFXOutputDev.cc @@ -2571,17 +2571,20 @@ void GFXOutputDev::preparePage(int pdfpage, int outputpage) if(!this->pages) { this->pagebuflen = 1024; + if(pdfpage > this->pagebuflen) + this->pagebuflen = pdfpage+1; this->pages = (int*)malloc(this->pagebuflen*sizeof(int)); memset(this->pages, -1, this->pagebuflen*sizeof(int)); - } else { - while(pdfpage >= this->pagebuflen) - { - int oldlen = this->pagebuflen; - this->pagebuflen+=1024; - this->pages = (int*)realloc(this->pages, this->pagebuflen*sizeof(int)); - memset(&this->pages[oldlen], -1, (this->pagebuflen-oldlen)*sizeof(int)); - } } + + while(pdfpage >= this->pagebuflen) + { + int oldlen = this->pagebuflen; + this->pagebuflen+=1024; + this->pages = (int*)realloc(this->pages, this->pagebuflen*sizeof(int)); + memset(&this->pages[oldlen], -1, (this->pagebuflen-oldlen)*sizeof(int)); + } + this->pages[pdfpage] = outputpage; if(pdfpage>this->pagepos) this->pagepos = pdfpage; -- 1.7.10.4