diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2008-08-16 15:12:07 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2008-08-16 15:12:07 +0000 |
commit | cfa558736324be5e2068f5459a55f882c2631bc6 (patch) | |
tree | d1677d1178c74630e3ad38e0fbbbcd54a467caf9 /xdelta3/testing/file.h | |
parent | d490e1971a6155e2637afbae6f13f97eee49ff95 (diff) |
Fix bug in xd3_merge_add(), calling memcpy with wrong offset and size.
Diffstat (limited to 'xdelta3/testing/file.h')
-rw-r--r-- | xdelta3/testing/file.h | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/xdelta3/testing/file.h b/xdelta3/testing/file.h index a0231be..30a8428 100644 --- a/xdelta3/testing/file.h +++ b/xdelta3/testing/file.h | |||
@@ -217,42 +217,58 @@ private: | |||
217 | size_t blksize_; | 217 | size_t blksize_; |
218 | }; | 218 | }; |
219 | 219 | ||
220 | class TmpFile { | 220 | class ExtFile { |
221 | public: | 221 | public: |
222 | // TODO this is a little unportable! | 222 | ExtFile() { |
223 | TmpFile() { | ||
224 | static int static_counter = 0; | 223 | static int static_counter = 0; |
225 | char buf[32]; | 224 | char buf[32]; |
226 | snprintf(buf, 32, "/tmp/regtest.%d", static_counter++); | 225 | snprintf(buf, 32, "/tmp/regtest.%d", static_counter++); |
227 | filename_.append(buf); | 226 | filename_.append(buf); |
228 | unlink(filename_.c_str()); | 227 | unlink(filename_.c_str()); |
228 | } | ||
229 | |||
230 | ~ExtFile() { | ||
231 | unlink(filename_.c_str()); | ||
232 | } | ||
233 | |||
234 | const char* Name() const { | ||
235 | return filename_.c_str(); | ||
236 | } | ||
237 | |||
238 | // Check whether a real file matches a file spec. | ||
239 | bool EqualsSpec(const FileSpec &spec) const; | ||
240 | |||
241 | protected: | ||
242 | string filename_; | ||
243 | }; | ||
244 | |||
245 | class TmpFile : public ExtFile { | ||
246 | public: | ||
247 | // TODO this is a little unportable! | ||
248 | TmpFile() { | ||
229 | main_file_init(&file_); | 249 | main_file_init(&file_); |
250 | CHECK_EQ(0, main_file_open(&file_, filename_.c_str(), XO_WRITE)); | ||
230 | } | 251 | } |
231 | 252 | ||
232 | ~TmpFile() { | 253 | ~TmpFile() { |
233 | unlink(filename_.c_str()); | ||
234 | main_file_cleanup(&file_); | 254 | main_file_cleanup(&file_); |
235 | } | 255 | } |
236 | 256 | ||
237 | void Append(const Block *block) { | 257 | void Append(const Block *block) { |
238 | if (!main_file_isopen(&file_)) { | ||
239 | CHECK_EQ(0, main_file_open(&file_, filename_.c_str(), XO_WRITE)); | ||
240 | } | ||
241 | CHECK_EQ(0, main_file_write(&file_, | 258 | CHECK_EQ(0, main_file_write(&file_, |
242 | block->Data(), block->Size(), | 259 | block->Data(), block->Size(), |
243 | "tmpfile write failed")); | 260 | "tmpfile write failed")); |
244 | } | 261 | } |
245 | 262 | ||
263 | |||
246 | const char* Name() const { | 264 | const char* Name() const { |
247 | CHECK_EQ(0, main_file_close(&file_)); | 265 | if (main_file_isopen(&file_)) { |
248 | return filename_.c_str(); | 266 | CHECK_EQ(0, main_file_close(&file_)); |
267 | } | ||
268 | return ExtFile::Name(); | ||
249 | } | 269 | } |
250 | 270 | ||
251 | // Check whether a real file matches a file spec. | ||
252 | bool EqualsSpec(const FileSpec &spec) const; | ||
253 | |||
254 | private: | 271 | private: |
255 | string filename_; | ||
256 | mutable main_file file_; | 272 | mutable main_file file_; |
257 | }; | 273 | }; |
258 | 274 | ||