[mlpack] 176/207: 1 : fix bug, wrong constructor 2 : use std::string to replace raw buffer

Barak A. Pearlmutter barak+git at pearlmutter.net
Thu Mar 23 17:53:51 UTC 2017


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch master
in repository mlpack.

commit c9f67a44ca0eaffb9d96bd24953bb7843cda88e4
Author: stereomatchingkiss <thamngapwei at gmail.com>
Date:   Sun Feb 19 12:30:05 2017 +0800

    1 : fix bug, wrong constructor
    2 : use std::string to replace raw buffer
---
 src/mlpack/core/data/load_impl.hpp | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/mlpack/core/data/load_impl.hpp b/src/mlpack/core/data/load_impl.hpp
index 0d4d992..acc9a8b 100644
--- a/src/mlpack/core/data/load_impl.hpp
+++ b/src/mlpack/core/data/load_impl.hpp
@@ -193,11 +193,10 @@ bool Load(const std::string& filename,
     // This is taken from load_auto_detect() in diskio_meat.hpp
     const std::string ARMA_MAT_TXT = "ARMA_MAT_TXT";
     //char* rawHeader = new char[ARMA_MAT_TXT.length() + 1];
-    std::string rawHeader(ARMA_MAT_TXT.length());
+    std::string rawHeader(ARMA_MAT_TXT.length(), '\0');
     std::streampos pos = stream.tellg();
 
     stream.read(&rawHeader[0], std::streamsize(ARMA_MAT_TXT.length()));
-    //rawHeader[ARMA_MAT_TXT.length()] = '\0';
     stream.clear();
     stream.seekg(pos); // Reset stream position after peeking.
 
@@ -222,17 +221,16 @@ bool Load(const std::string& filename,
   {
     // This could be raw binary or Armadillo binary (binary with header).  We
     // will check to see if it is Armadillo binary.
-    const std::string ARMA_MAT_BIN = "ARMA_MAT_BIN";
-    char *rawHeader = new char[ARMA_MAT_BIN.length() + 1];
+    const std::string ARMA_MAT_BIN = "ARMA_MAT_BIN";    
+    std::string rawHeader(ARMA_MAT_BIN.length(), '\0');
 
     std::streampos pos = stream.tellg();
 
-    stream.read(rawHeader, std::streamsize(ARMA_MAT_BIN.length()));
-    rawHeader[ARMA_MAT_BIN.length()] = '\0';
+    stream.read(&rawHeader[0], std::streamsize(ARMA_MAT_BIN.length()));
     stream.clear();
     stream.seekg(pos); // Reset stream position after peeking.
 
-    if (std::string(rawHeader) == ARMA_MAT_BIN)
+    if (rawHeader == ARMA_MAT_BIN)
     {
       stringType = "Armadillo binary formatted data";
       loadType = arma::arma_binary;
@@ -241,9 +239,7 @@ bool Load(const std::string& filename,
     {
       stringType = "raw binary formatted data";
       loadType = arma::raw_binary;
-    }
-
-    delete[] rawHeader;
+    }    
   }
   else if (extension == "pgm")
   {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list