From 9c763a8c5863bd7a576cfe67c38672a0cf71b06a Mon Sep 17 00:00:00 2001 From: graehl Date: Wed, 21 Jul 2010 02:54:09 +0000 Subject: vest generate options valgrind fix git-svn-id: https://ws10smt.googlecode.com/svn/trunk@352 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/filelib.h | 10 ++++++---- decoder/gzstream.cc | 6 ++++-- decoder/stringlib_test.cc | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'decoder') 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::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(new igzstream(filename.c_str())) : - static_cast(new std::ifstream(filename.c_str()))); + static_cast(new igzstream(file)) : + static_cast(new std::ifstream(file))); if (!*ps_) { std::cerr << "Failed to open " << filename << std::endl; abort(); @@ -79,9 +80,10 @@ class WriteFile : public BaseFile { 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(new ogzstream(filename.c_str())) : - static_cast(new std::ofstream(filename.c_str()))); + static_cast(new ogzstream(file)) : + static_cast(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