Fix allocation bug for CachedText
authorkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Tue, 3 Mar 2009 00:45:04 +0000 (00:45 +0000)
committerkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Tue, 3 Mar 2009 00:45:04 +0000 (00:45 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@202 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

XMLTree.cpp
XMLTree.h

index a37263a..62ca3fd 100644 (file)
@@ -103,16 +103,15 @@ void XMLTree::Save(unsigned char *filename)
     Tags->save(fp);\r
 \r
     // stores the texts   \r
-    if (!disable_tc)\r
+    if (!disable_tc) {\r
       Text->Save(fp);\r
-    if (!disable_tc){\r
-    int st = CachedText.size();\r
-    ufwrite(&st, sizeof(int),1,fp);\r
-    for (int i = 0; i< CachedText.size(); ++i){\r
-      st = CachedText.at(i).size();\r
+      int st = CachedText.size();\r
       ufwrite(&st, sizeof(int),1,fp);\r
-      ufwrite(CachedText.at(i).c_str(),sizeof(char),(1+strlen(CachedText.at(i).c_str())),fp);\r
-    };\r
+      for (int i = 0; i< CachedText.size(); i++){\r
+       st = CachedText.at(i).size();\r
+       ufwrite(&st, sizeof(int),1,fp);\r
+       ufwrite(CachedText.at(i).c_str(),sizeof(char),1+CachedText.at(i).size(),fp);\r
+      };\r
     };\r
     fclose(fp);\r
 \r
@@ -213,9 +212,9 @@ XMLTree *XMLTree::Load(unsigned char *filename, int sample_rate_text)
       };\r
 \r
     }\r
-    else\r
+    else {\r
       XML_Tree->Text = NULL;\r
-\r
+    }\r
     s_text = ftell(fp) - s_text;\r
 \r
     \r
@@ -780,7 +779,7 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text,bool dtc)
     found_attributes = false;\r
     npar = 0;\r
     parArraySize = 1;\r
-    ntagnames = 2;    \r
+    ntagnames = 4;    \r
     disable_tc = dtc;\r
     \r
     indexing_empty_texts = empty_texts;\r
@@ -789,7 +788,7 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text,bool dtc)
     \r
     tags_aux = (TagType *) umalloc(sizeof(TagType));\r
     \r
-    TagName = (unsigned char **) umalloc(2*sizeof(unsigned char*));\r
+    TagName = (unsigned char **) umalloc(4*sizeof(unsigned char*));\r
 \r
     TagName[0] = (unsigned char *) umalloc(4*sizeof(unsigned char));\r
 \r
@@ -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));\r
 \r
     strcpy((char *) TagName[1], "<$>");\r
+    \r
+    //OJO need to put these in the table too.\r
+    TagName[2] = (unsigned char *) umalloc(5*sizeof(unsigned char));\r
+\r
+    strcpy((char *) TagName[2], "/<@>");\r
+\r
+    TagName[3] = (unsigned char *) umalloc(5*sizeof(unsigned char));\r
+\r
+    strcpy((char *) TagName[3], "/<$>");\r
 \r
 \r
     if (!indexing_empty_texts) \r
index c6542a0..b6aa410 100644 (file)
--- a/XMLTree.h
+++ b/XMLTree.h
@@ -401,7 +401,8 @@ public:
    }\r
 \r
    uchar* GetCachedText(DocID d) {\r
-     uchar * str = (uchar*) calloc(sizeof(char),(CachedText.at(d).size() + 1));     \r
+     uchar * str = (uchar*) calloc(sizeof(char),(CachedText.at(d).size() + 1));\r
+     strcpy((char*) str,(const char*) CachedText.at(d).c_str());\r
      return (uchar*) (str);\r
    }\r
    \r