From ac53090f1525b3ef9cbde0b51da5fbb238a06744 Mon Sep 17 00:00:00 2001 From: kim Date: Tue, 3 Mar 2009 00:45:04 +0000 Subject: [PATCH] Fix allocation bug for CachedText git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@202 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- XMLTree.cpp | 32 ++++++++++++++++++++------------ XMLTree.h | 3 ++- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/XMLTree.cpp b/XMLTree.cpp index a37263a..62ca3fd 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -103,16 +103,15 @@ void XMLTree::Save(unsigned char *filename) Tags->save(fp); // stores the texts - if (!disable_tc) + if (!disable_tc) { Text->Save(fp); - if (!disable_tc){ - int st = CachedText.size(); - ufwrite(&st, sizeof(int),1,fp); - for (int i = 0; i< CachedText.size(); ++i){ - st = CachedText.at(i).size(); + int st = CachedText.size(); ufwrite(&st, sizeof(int),1,fp); - ufwrite(CachedText.at(i).c_str(),sizeof(char),(1+strlen(CachedText.at(i).c_str())),fp); - }; + for (int i = 0; i< CachedText.size(); i++){ + st = CachedText.at(i).size(); + ufwrite(&st, sizeof(int),1,fp); + ufwrite(CachedText.at(i).c_str(),sizeof(char),1+CachedText.at(i).size(),fp); + }; }; fclose(fp); @@ -213,9 +212,9 @@ XMLTree *XMLTree::Load(unsigned char *filename, int sample_rate_text) }; } - else + else { XML_Tree->Text = NULL; - + } s_text = ftell(fp) - s_text; @@ -780,7 +779,7 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text,bool dtc) found_attributes = false; npar = 0; parArraySize = 1; - ntagnames = 2; + ntagnames = 4; disable_tc = dtc; indexing_empty_texts = empty_texts; @@ -789,7 +788,7 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text,bool dtc) tags_aux = (TagType *) umalloc(sizeof(TagType)); - TagName = (unsigned char **) umalloc(2*sizeof(unsigned char*)); + TagName = (unsigned char **) umalloc(4*sizeof(unsigned char*)); TagName[0] = (unsigned char *) umalloc(4*sizeof(unsigned char)); @@ -798,6 +797,15 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text,bool dtc) TagName[1] = (unsigned char *) umalloc(4*sizeof(unsigned char)); strcpy((char *) TagName[1], "<$>"); + + //OJO need to put these in the table too. + TagName[2] = (unsigned char *) umalloc(5*sizeof(unsigned char)); + + strcpy((char *) TagName[2], "/<@>"); + + TagName[3] = (unsigned char *) umalloc(5*sizeof(unsigned char)); + + strcpy((char *) TagName[3], "/<$>"); if (!indexing_empty_texts) diff --git a/XMLTree.h b/XMLTree.h index c6542a0..b6aa410 100644 --- a/XMLTree.h +++ b/XMLTree.h @@ -401,7 +401,8 @@ public: } uchar* GetCachedText(DocID d) { - uchar * str = (uchar*) calloc(sizeof(char),(CachedText.at(d).size() + 1)); + uchar * str = (uchar*) calloc(sizeof(char),(CachedText.at(d).size() + 1)); + strcpy((char*) str,(const char*) CachedText.at(d).c_str()); return (uchar*) (str); } -- 2.17.1