diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-21 02:54:09 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-21 02:54:09 +0000 |
commit | e14043e62b765863584a3b42a0c5b6bd11d5bd4f (patch) | |
tree | 386c61152a280ca6f52c83ad28ce120b79711a17 /decoder | |
parent | e4479d3ce5ef5df978ee6183c74c30dfba8a7539 (diff) |
vest generate options valgrind fix
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@352 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder')
-rw-r--r-- | decoder/filelib.h | 10 | ||||
-rw-r--r-- | decoder/gzstream.cc | 6 | ||||
-rwxr-xr-x | decoder/stringlib_test.cc | 2 |
3 files changed, 11 insertions, 7 deletions
diff --git a/decoder/filelib.h b/decoder/filelib.h index 85e1c29a..9f6bd0a9 100644 --- a/decoder/filelib.h +++ b/decoder/filelib.h @@ -58,9 +58,10 @@ class ReadFile : public BaseFile<std::istream> { std::cerr << "File does not exist: " << filename << std::endl; abort(); } + char const* file=filename_.c_str(); // just in case the gzstream keeps using the filename for longer than the constructor, e.g. inflateReset2. warning in valgrind that I'm hoping will disappear - it makes no sense. ps_.reset(EndsWith(filename, ".gz") ? - static_cast<std::istream*>(new igzstream(filename.c_str())) : - static_cast<std::istream*>(new std::ifstream(filename.c_str()))); + static_cast<std::istream*>(new igzstream(file)) : + static_cast<std::istream*>(new std::ifstream(file))); if (!*ps_) { std::cerr << "Failed to open " << filename << std::endl; abort(); @@ -79,9 +80,10 @@ class WriteFile : public BaseFile<std::ostream> { if (is_std()) { ps_=PS(&std::cout,file_null_deleter()); } else { + char const* file=filename_.c_str(); // just in case the gzstream keeps using the filename for longer than the constructor, e.g. inflateReset2. warning in valgrind that I'm hoping will disappear - it makes no sense. ps_.reset(EndsWith(filename, ".gz") ? - static_cast<std::ostream*>(new ogzstream(filename.c_str())) : - static_cast<std::ostream*>(new std::ofstream(filename.c_str()))); + static_cast<std::ostream*>(new ogzstream(file)) : + static_cast<std::ostream*>(new std::ofstream(file))); if (!*ps_) { std::cerr << "Failed to open " << filename << std::endl; abort(); diff --git a/decoder/gzstream.cc b/decoder/gzstream.cc index 9678355b..88cd1bd2 100644 --- a/decoder/gzstream.cc +++ b/decoder/gzstream.cc @@ -51,14 +51,16 @@ gzstreambuf* gzstreambuf::open( const char* name, int open_mode) { if ((mode & std::ios::ate) || (mode & std::ios::app) || ((mode & std::ios::in) && (mode & std::ios::out))) return (gzstreambuf*)0; - char fmode[10]; + const int Nmode=10; + char fmode[Nmode]; char* fmodeptr = fmode; if ( mode & std::ios::in) *fmodeptr++ = 'r'; else if ( mode & std::ios::out) *fmodeptr++ = 'w'; *fmodeptr++ = 'b'; - *fmodeptr = '\0'; + while (fmodeptr<fmode+Nmode) // hopefully wil help valgrind + *fmodeptr++ = '\0'; file = gzopen( name, fmode); if (!file) handle_gzerror(); if (file == 0) diff --git a/decoder/stringlib_test.cc b/decoder/stringlib_test.cc index ea39f30f..f66cdbeb 100755 --- a/decoder/stringlib_test.cc +++ b/decoder/stringlib_test.cc @@ -9,8 +9,8 @@ struct print { } }; +char p[]=" 1 are u 2 serious?"; int main(int argc, char *argv[]) { - char *p=" 1 are u 2 serious?"; std::string const& w="verylongword"; VisitTokens(p,print()); VisitTokens(w,print()); |