Salome HOME
fix bug of invalid file read - a garbage is in the end of string data
authorinv <inv@opencascade.com>
Fri, 6 Dec 2013 05:57:02 +0000 (05:57 +0000)
committerinv <inv@opencascade.com>
Fri, 6 Dec 2013 05:57:02 +0000 (05:57 +0000)
src/XAO/tests/TestUtils.hxx

index 83e3436806df3f47cf6d6a287e1b2d197bf22194..137b795885010243bc7c4d45c9aa4edc67d04ce3 100644 (file)
@@ -24,9 +24,11 @@ namespace XAO
             rstr.open(filePath.c_str());
             rstr.seekg(0, rstr.end);        // go to the end
             length = rstr.tellg();          // report location (this is the length)
+            printf("---------------------------VSR: length=%ld\n", length);
             rstr.seekg(0, rstr.beg);        // go back to the beginning
-            char* txt = new char[length];   // allocate memory for a buffer of appropriate dimension
+            char* txt = new char[length+1]; // allocate memory for a buffer of appropriate dimension
             rstr.read(txt, length);         // read the whole file into the buffer
+            txt[length] = '\0';
             rstr.close();
 
             return txt;