diff options
Diffstat (limited to 'xdelta3/testing/file.h')
-rw-r--r-- | xdelta3/testing/file.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/xdelta3/testing/file.h b/xdelta3/testing/file.h index a204d74..67309ac 100644 --- a/xdelta3/testing/file.h +++ b/xdelta3/testing/file.h | |||
@@ -82,16 +82,21 @@ public: | |||
82 | } | 82 | } |
83 | 83 | ||
84 | void SetSize(size_t size) { | 84 | void SetSize(size_t size) { |
85 | size_ = size; | 85 | uint8_t *t = NULL; |
86 | |||
87 | if (data_size_ < size) { | 86 | if (data_size_ < size) { |
88 | if (data_) { | 87 | if (data_) { |
89 | delete [] data_; | 88 | t = data_; |
90 | } | 89 | } |
91 | data_ = new uint8_t[size]; | 90 | data_ = new uint8_t[size]; |
92 | data_size_ = size; | 91 | data_size_ = size; |
93 | } | 92 | } |
93 | if (t && size < size_) { | ||
94 | memcpy(data_, t, size); | ||
95 | } | ||
96 | delete [] t; | ||
97 | size_ = size; | ||
94 | } | 98 | } |
99 | |||
95 | private: | 100 | private: |
96 | friend class BlockIterator; | 101 | friend class BlockIterator; |
97 | 102 | ||
@@ -268,6 +273,7 @@ public: | |||
268 | } | 273 | } |
269 | 274 | ||
270 | void SetBlock(xoff_t blkno) { | 275 | void SetBlock(xoff_t blkno) { |
276 | CHECK_LE(blkno, Blocks()); | ||
271 | blkno_ = blkno; | 277 | blkno_ = blkno; |
272 | } | 278 | } |
273 | 279 | ||
@@ -373,4 +379,3 @@ public: | |||
373 | private: | 379 | private: |
374 | mutable main_file file_; | 380 | mutable main_file file_; |
375 | }; | 381 | }; |
376 | |||