@@ -37,30 +37,23 @@ int main(int argc, char* const argv[]) {
37
37
const char * ba = argv[5 ]; // block argument
38
38
39
39
if (argc >= 5 ) {
40
- int blocksize = argc == 6 ? atoi (ba) : 10000 ;
41
- // ensure blocksize is sane
42
- if (blocksize > 1024 * 1024 )
43
- blocksize = 10000 ;
44
-
45
- std::vector<Exiv2::byte> bytes (blocksize);
46
-
47
40
// copy fileIn from a remote location.
48
41
auto io = Exiv2::ImageFactory::createIo (fr);
49
42
if (io->open () != 0 ) {
50
- Error (Exiv2::ErrorCode::kerFileOpenFailed, io->path (), " rb" , strError ());
43
+ throw Error (Exiv2::ErrorCode::kerFileOpenFailed, io->path (), " rb" , strError ());
51
44
}
52
45
FileIo output (f0);
53
46
if (!output.open (" wb" )) {
54
47
Error (Exiv2::ErrorCode::kerFileOpenFailed, output.path (), " w+b" , strError ());
55
48
}
56
- size_t l = 0 ;
57
- if (!bytes.empty ()) {
58
- size_t r;
59
- while ((r = io->read (bytes.data (), blocksize)) > 0 ) {
60
- l += r;
61
- output.write (bytes.data (), r);
49
+ int blocksize = std::min (argc == 6 ? atoi (ba) : 10000 , 1024 * 1024 );
50
+ if (blocksize > 0 ) {
51
+ auto bytes = std::make_unique<Exiv2::byte[]>(blocksize);
52
+ while (auto r = io->read (bytes.get (), blocksize)) {
53
+ output.write (bytes.get (), r);
62
54
}
63
55
} else {
56
+ size_t l = 0 ;
64
57
// read/write byte-wise (#1029)
65
58
while (l++ < io->size ()) {
66
59
output.putb (io->getb ());
@@ -118,9 +111,8 @@ int main(int argc, char* const argv[]) {
118
111
throw Error (Exiv2::ErrorCode::kerFileOpenFailed, f2, " w+b" , strError ());
119
112
}
120
113
121
- size_t readCount = 0 ;
122
114
byte buf[32 ];
123
- while (( readCount = fileOut1.read (buf, sizeof (buf) ))) {
115
+ while (auto readCount = fileOut1.read (buf, sizeof (buf))) {
124
116
if (memIo2.write (buf, readCount) != readCount) {
125
117
std::cerr << argv[0 ] << " : MemIo bad write 2\n " ;
126
118
return 13 ;
0 commit comments