Skip to content

Commit 9ff72e5

Browse files
Make offset=0 the default parameter.
1 parent aec6733 commit 9ff72e5

36 files changed

+250
-250
lines changed

fuzz/fuzz-read-print-write.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size) {
1717
try {
1818
Exiv2::DataBuf data_copy(data, size);
1919
Exiv2::Image::UniquePtr image =
20-
Exiv2::ImageFactory::open(data_copy.c_data(0), size);
20+
Exiv2::ImageFactory::open(data_copy.c_data(), size);
2121
assert(image.get() != 0);
2222

2323
image->readMetadata();

include/exiv2/types.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,13 @@ namespace Exiv2 {
256256
int cmpBytes(size_t offset, const void* buf, size_t bufsize) const;
257257

258258
//! Returns a data pointer.
259-
byte* data(size_t offset);
259+
byte* data(size_t offset = 0);
260260

261261
//! Returns a (read-only) data pointer.
262-
const byte* c_data(size_t offset) const;
262+
const byte* c_data(size_t offset = 0) const;
263263

264264
//! Returns a (read-only) C-style string pointer.
265-
const char* c_str(size_t offset) const;
265+
const char* c_str(size_t offset = 0) const;
266266

267267
private:
268268
// DATA

samples/largeiptc-test.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int main(int argc, char* const argv[])
4747
}
4848
Exiv2::DataBuf buf(static_cast<long>(io.size()));
4949
std::cout << "Reading " << buf.size() << " bytes from " << data << "\n";
50-
long readBytes = io.read(buf.data(0), buf.size());
50+
long readBytes = io.read(buf.data(), buf.size());
5151
if (readBytes != buf.size() || io.error() || io.eof()) {
5252
throw Exiv2::Error(Exiv2::kerFailedToReadImageData);
5353
}
@@ -59,7 +59,7 @@ int main(int argc, char* const argv[])
5959

6060
// Set Preview field to the content of the data file
6161
Exiv2::DataValue value;
62-
value.read(buf.data(0), buf.size());
62+
value.read(buf.data(), buf.size());
6363
Exiv2::IptcData& iptcData = image->iptcData();
6464
std::cout << "IPTC fields: " << iptcData.size() << "\n";
6565
iptcData["Iptc.Application2.Preview"] = value;
@@ -71,7 +71,7 @@ int main(int argc, char* const argv[])
7171
const Exiv2::byte* record;
7272
uint32_t sizeHdr = 0;
7373
uint32_t sizeData = 0;
74-
Exiv2::Photoshop::locateIptcIrb(irb.data(0), irb.size(), &record, &sizeHdr, &sizeData);
74+
Exiv2::Photoshop::locateIptcIrb(irb.data(), irb.size(), &record, &sizeHdr, &sizeData);
7575
Exiv2::DataBuf rawIptc = Exiv2::IptcParser::encode(iptcData);
7676
std::cout << "Comparing IPTC and IRB size... ";
7777
if (static_cast<uint32_t>(rawIptc.size()) != sizeData) {

samples/mmap-test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ try {
5252
// Read from the memory mapped region
5353
buf.copyBytes(0, pData, buf.size());
5454
// Reopen file in write mode and write to it
55-
file.write(buf.c_data(0), buf.size());
55+
file.write(buf.c_data(), buf.size());
5656
// Read from the mapped region again
5757
buf.copyBytes(0, pData, buf.size());
5858
file.close();

samples/mrwthumb.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int main(int argc, char* const argv[])
6161
Exiv2::FileIo file("img_thumb.jpg");
6262

6363
file.open("wb");
64-
file.write(buf.c_data(0), buf.size());
64+
file.write(buf.c_data(), buf.size());
6565
file.close();
6666
}
6767

samples/tiff-test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void mini1(const char* path)
7373

7474
// Write nothing, this time with a previous binary image
7575
DataBuf buf = readFile(path);
76-
wm = ExifParser::encode(blob, buf.c_data(0), buf.size(), bigEndian, exifData);
76+
wm = ExifParser::encode(blob, buf.c_data(), buf.size(), bigEndian, exifData);
7777
enforce(wm == wmIntrusive, Exiv2::kerErrorMessage, "encode returned an unexpected value");
7878
assert(blob.empty());
7979
std::cout << "Test 2: Writing empty Exif data with original binary data: ok.\n";

samples/xmpparse.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ try {
3939
}
4040
Exiv2::DataBuf buf = Exiv2::readFile(argv[1]);
4141
std::string xmpPacket;
42-
xmpPacket.assign(buf.c_str(0), buf.size());
42+
xmpPacket.assign(buf.c_str(), buf.size());
4343
Exiv2::XmpData xmpData;
4444
if (0 != Exiv2::XmpParser::decode(xmpData, xmpPacket)) {
4545
std::string error(argv[1]);

samples/xmpparser-test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ try {
4040
std::string filename(argv[1]);
4141
Exiv2::DataBuf buf = Exiv2::readFile(filename);
4242
std::string xmpPacket;
43-
xmpPacket.assign(buf.c_str(0), buf.size());
43+
xmpPacket.assign(buf.c_str(), buf.size());
4444
std::cerr << "-----> Decoding XMP data read from " << filename << " <-----\n";
4545
Exiv2::XmpData xmpData;
4646
if (0 != Exiv2::XmpParser::decode(xmpData, xmpPacket)) {

src/actions.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ namespace Action {
232232
Exiv2::DataBuf ascii(static_cast<long>(size * 3 + 1));
233233
ascii.write_uint8(size * 3, 0);
234234
iccProfile.copyBytes(0,output.str().c_str(),size);
235-
if (Exiv2::base64encode(iccProfile.c_data(0), size, reinterpret_cast<char*>(ascii.data(0)), size * 3)) {
235+
if (Exiv2::base64encode(iccProfile.c_data(), size, reinterpret_cast<char*>(ascii.data()), size * 3)) {
236236
long chunk = 60 ;
237-
std::string code = std::string("data:") + std::string(ascii.c_str(0));
237+
std::string code = std::string("data:") + std::string(ascii.c_str());
238238
long length = static_cast<long>(code.size());
239239
for ( long start = 0 ; start < length ; start += chunk ) {
240240
long count = (start+chunk) < length ? chunk : length - start ;
@@ -615,8 +615,8 @@ namespace Action {
615615
std::cout << std::endl;
616616
first = false;
617617
Exiv2::DataBuf buf(md.size());
618-
md.copy(buf.data(0), pImage->byteOrder());
619-
Exiv2::hexdump(std::cout, buf.c_data(0), buf.size());
618+
md.copy(buf.data(), pImage->byteOrder());
619+
Exiv2::hexdump(std::cout, buf.c_data(), buf.size());
620620
}
621621
std::cout << std::endl;
622622
return true;
@@ -1025,15 +1025,15 @@ namespace Action {
10251025
} else {
10261026

10271027
if ( bStdout ) { // -eC-
1028-
std::cout.write(image->iccProfile()->c_str(0),
1028+
std::cout.write(image->iccProfile()->c_str(),
10291029
image->iccProfile()->size());
10301030
} else {
10311031
if (Params::instance().verbose_) {
10321032
std::cout << _("Writing iccProfile: ") << target << std::endl;
10331033
}
10341034
Exiv2::FileIo iccFile(target);
10351035
iccFile.open("wb") ;
1036-
iccFile.write(image->iccProfile()->c_data(0),image->iccProfile()->size());
1036+
iccFile.write(image->iccProfile()->c_data(),image->iccProfile()->size());
10371037
iccFile.close();
10381038
}
10391039
}
@@ -1888,7 +1888,7 @@ namespace {
18881888

18891889
Exiv2::DataBuf stdIn;
18901890
if ( bStdin ) Params::instance().getStdin(stdIn);
1891-
Exiv2::BasicIo::UniquePtr ioStdin = Exiv2::BasicIo::UniquePtr(new Exiv2::MemIo(stdIn.c_data(0),stdIn.size()));
1891+
Exiv2::BasicIo::UniquePtr ioStdin = Exiv2::BasicIo::UniquePtr(new Exiv2::MemIo(stdIn.c_data(),stdIn.size()));
18921892

18931893
Exiv2::Image::UniquePtr sourceImage = bStdin ? Exiv2::ImageFactory::open(std::move(ioStdin)) : Exiv2::ImageFactory::open(source);
18941894
assert(sourceImage.get() != 0);

src/basicio.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ namespace Exiv2 {
516516
#else
517517
// Workaround for platforms without mmap: Read the file into memory
518518
DataBuf buf(static_cast<long>(p_->mappedLength_));
519-
if (read(buf.data(0), buf.size()) != buf.size()) {
519+
if (read(buf.data(), buf.size()) != buf.size()) {
520520
#ifdef EXV_UNICODE_PATH
521521
if (p_->wpMode_ == Impl::wpUnicode) {
522522
throw WError(kerCallFailed, wpath(), strError().c_str(), "FileIo::read");
@@ -671,7 +671,7 @@ namespace Exiv2 {
671671
if (statOk && S_ISLNK(buf1.st_mode)) {
672672
lbuf.alloc(buf1.st_size + 1);
673673
lbuf.clear();
674-
pf = reinterpret_cast<char*>(lbuf.data(0));
674+
pf = reinterpret_cast<char*>(lbuf.data());
675675
if (::readlink(path().c_str(), pf, lbuf.size() - 1) == -1) {
676676
throw Error(kerCallFailed, path(), strError(), "readlink");
677677
}
@@ -990,7 +990,7 @@ namespace Exiv2 {
990990
if (static_cast<size_t>(rcount) > size())
991991
throw Error(kerInvalidMalloc);
992992
DataBuf buf(rcount);
993-
long readCount = read(buf.data(0), buf.size());
993+
long readCount = read(buf.data(), buf.size());
994994
if (readCount < 0) {
995995
throw Error(kerInputDataReadFailed);
996996
}
@@ -1351,7 +1351,7 @@ namespace Exiv2 {
13511351
DataBuf MemIo::read(long rcount)
13521352
{
13531353
DataBuf buf(rcount);
1354-
long readCount = read(buf.data(0), buf.size());
1354+
long readCount = read(buf.data(), buf.size());
13551355
if (readCount < 0) {
13561356
throw Error(kerInputDataReadFailed);
13571357
}
@@ -1831,7 +1831,7 @@ namespace Exiv2 {
18311831
DataBuf RemoteIo::read(long rcount)
18321832
{
18331833
DataBuf buf(rcount);
1834-
long readCount = read(buf.data(0), buf.size());
1834+
long readCount = read(buf.data(), buf.size());
18351835
if (readCount < 0) {
18361836
throw Error(kerInputDataReadFailed);
18371837
}
@@ -2442,7 +2442,7 @@ namespace Exiv2 {
24422442
throw Error(kerCallFailed, path, strError(), "::stat");
24432443
}
24442444
DataBuf buf(st.st_size);
2445-
long len = file.read(buf.data(0), buf.size());
2445+
long len = file.read(buf.data(), buf.size());
24462446
if (len != buf.size()) {
24472447
throw Error(kerCallFailed, path, strError(), "FileIo::read");
24482448
}
@@ -2461,7 +2461,7 @@ namespace Exiv2 {
24612461
throw WError(kerCallFailed, wpath, strError().c_str(), "::_wstat");
24622462
}
24632463
DataBuf buf(st.st_size);
2464-
long len = file.read(buf.data(0), buf.size());
2464+
long len = file.read(buf.data(), buf.size());
24652465
if (len != buf.size()) {
24662466
throw WError(kerCallFailed, wpath, strError().c_str(), "FileIo::read");
24672467
}
@@ -2475,7 +2475,7 @@ namespace Exiv2 {
24752475
if (file.open("wb") != 0) {
24762476
throw Error(kerFileOpenFailed, path, "wb", strError());
24772477
}
2478-
return file.write(buf.c_data(0), buf.size());
2478+
return file.write(buf.c_data(), buf.size());
24792479
}
24802480

24812481
#ifdef EXV_UNICODE_PATH
@@ -2485,7 +2485,7 @@ namespace Exiv2 {
24852485
if (file.open("wb") != 0) {
24862486
throw WError(kerFileOpenFailed, wpath, "wb", strError().c_str());
24872487
}
2488-
return file.write(buf.c_data(0), buf.size());
2488+
return file.write(buf.c_data(), buf.size());
24892489
}
24902490

24912491
#endif

src/bmffimage.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ namespace Exiv2
220220
hdrsize += 8;
221221
enforce(hdrsize <= static_cast<size_t>(pbox_end - address), Exiv2::kerCorruptedMetadata);
222222
DataBuf data(8);
223-
io_->read(data.data(0), data.size());
223+
io_->read(data.data(), data.size());
224224
box_length = data.read_uint64(0, endian_);
225225
}
226226

@@ -230,7 +230,7 @@ namespace Exiv2
230230
enforce(box_length - hdrsize <= static_cast<size_t>(pbox_end - restore), Exiv2::kerCorruptedMetadata);
231231
DataBuf data(static_cast<long>(box_length - hdrsize));
232232
const long box_end = restore + data.size();
233-
io_->read(data.data(0), data.size());
233+
io_->read(data.data(), data.size());
234234
io_->seek(restore, BasicIo::beg);
235235

236236
long skip = 0; // read position in data.pData_
@@ -407,7 +407,7 @@ namespace Exiv2
407407
uint8_t meth = data.read_uint8(skip+0);
408408
uint8_t prec = data.read_uint8(skip+1);
409409
uint8_t approx = data.read_uint8(skip+2);
410-
std::string colour_type = std::string(data.c_str(0), 4);
410+
std::string colour_type = std::string(data.c_str(), 4);
411411
skip+=4;
412412
if ( colour_type == "rICC" || colour_type == "prof" ) {
413413
DataBuf profile(data.c_data(skip),data.size()-skip);
@@ -423,7 +423,7 @@ namespace Exiv2
423423

424424
case TAG_uuid: {
425425
DataBuf uuid(16);
426-
io_->read(uuid.data(0), uuid.size());
426+
io_->read(uuid.data(), uuid.size());
427427
std::string name = uuidName(uuid);
428428
if ( bTrace ) {
429429
out << " uuidName " << name << std::endl;
@@ -476,7 +476,7 @@ namespace Exiv2
476476
long restore = io_->tell();
477477
DataBuf exif(static_cast<long>(length));
478478
io_->seek(static_cast<long>(start),BasicIo::beg);
479-
if ( exif.size() > 8 && io_->read(exif.data(0),exif.size()) == exif.size() ) {
479+
if ( exif.size() > 8 && io_->read(exif.data(),exif.size()) == exif.size() ) {
480480
// hunt for "II" or "MM"
481481
long eof = 0xffffffff; // impossible value for punt
482482
long punt = eof;
@@ -500,15 +500,15 @@ namespace Exiv2
500500
enforce(length - 8 <= io_->size() - io_->tell(), kerCorruptedMetadata);
501501
enforce(length - 8 <= static_cast<unsigned long>(std::numeric_limits<long>::max()), kerCorruptedMetadata);
502502
DataBuf data(static_cast<long>(length - 8));
503-
long bufRead = io_->read(data.data(0), data.size());
503+
long bufRead = io_->read(data.data(), data.size());
504504

505505
if (io_->error())
506506
throw Error(kerFailedToReadImageData);
507507
if (bufRead != data.size())
508508
throw Error(kerInputDataReadFailed);
509509

510510
Internal::TiffParserWorker::decode(exifData(), iptcData(), xmpData(),
511-
data.c_data(0), data.size(), root_tag,
511+
data.c_data(), data.size(), root_tag,
512512
Internal::TiffMapping::findDecoder);
513513
}
514514
}
@@ -526,12 +526,12 @@ namespace Exiv2
526526
enforce(length < static_cast<unsigned long>(std::numeric_limits<long>::max()), kerCorruptedMetadata);
527527
DataBuf xmp(static_cast<long>(length+1));
528528
xmp.write_uint8(static_cast<size_t>(length), 0); // ensure xmp is null terminated!
529-
if ( io_->read(xmp.data(0), static_cast<long>(length)) != static_cast<long>(length) )
529+
if ( io_->read(xmp.data(), static_cast<long>(length)) != static_cast<long>(length) )
530530
throw Error(kerInputDataReadFailed);
531531
if ( io_->error() )
532532
throw Error(kerFailedToReadImageData);
533533
try {
534-
Exiv2::XmpParser::decode(xmpData(), std::string(xmp.c_str(0)));
534+
Exiv2::XmpParser::decode(xmpData(), std::string(xmp.c_str()));
535535
} catch (...) {
536536
throw Error(kerFailedToReadImageData);
537537
}
@@ -588,7 +588,7 @@ namespace Exiv2
588588
default: break; // do nothing
589589

590590
case kpsIccProfile : {
591-
out.write(iccProfile_.c_str(0), iccProfile_.size());
591+
out.write(iccProfile_.c_str(), iccProfile_.size());
592592
} break;
593593

594594
#ifdef EXV_HAVE_XMP_TOOLKIT

src/convert.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,8 @@ namespace Exiv2 {
11951195
auto pos = exifData_->findKey(key);
11961196
if (pos == exifData_->end()) continue;
11971197
DataBuf data(pos->size());
1198-
pos->copy(data.data(0), littleEndian /* FIXME ? */);
1199-
MD5Update ( &context, data.c_data(0), data.size());
1198+
pos->copy(data.data(), littleEndian /* FIXME ? */);
1199+
MD5Update ( &context, data.c_data(), data.size());
12001200
}
12011201
}
12021202
MD5Final(digest, &context);
@@ -1266,7 +1266,7 @@ namespace Exiv2 {
12661266
MD5Init(&context);
12671267

12681268
DataBuf data = IptcParser::encode(*iptcData_);
1269-
MD5Update(&context, data.c_data(0), data.size());
1269+
MD5Update(&context, data.c_data(), data.size());
12701270
MD5Final(digest, &context);
12711271
res << std::setw(2) << std::setfill('0') << std::hex << std::uppercase;
12721272
for (auto&& i : digest) {

src/crwimage.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace Exiv2 {
102102
}
103103
clearMetadata();
104104
DataBuf file(static_cast<long>(io().size()));
105-
io_->read(file.data(0), file.size());
105+
io_->read(file.data(), file.size());
106106

107107
CrwParser::decode(this, io_->mmap(), static_cast<uint32_t>(io_->size()));
108108

@@ -121,15 +121,15 @@ namespace Exiv2 {
121121
if (isCrwType(*io_, false)) {
122122
// Read the image into a memory buffer
123123
buf.alloc(static_cast<long>(io_->size()));
124-
io_->read(buf.data(0), buf.size());
124+
io_->read(buf.data(), buf.size());
125125
if (io_->error() || io_->eof()) {
126126
buf.reset();
127127
}
128128
}
129129
}
130130

131131
Blob blob;
132-
CrwParser::encode(blob, buf.c_data(0), buf.size(), this);
132+
CrwParser::encode(blob, buf.c_data(), buf.size(), this);
133133

134134
// Write new buffer to file
135135
MemIo::UniquePtr tempIo(new MemIo);

src/crwimage_int.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ namespace Exiv2 {
10281028
// Set the new value or remove the entry
10291029
if (ed != image.exifData().end()) {
10301030
DataBuf buf(ed->size());
1031-
ed->copy(buf.data(0), pHead->byteOrder());
1031+
ed->copy(buf.data(), pHead->byteOrder());
10321032
pHead->add(pCrwMapping->crwTagId_, pCrwMapping->crwDir_, buf);
10331033
}
10341034
else {
@@ -1085,7 +1085,7 @@ namespace Exiv2 {
10851085
DataBuf buf(size);
10861086
long pos = 0;
10871087
if (ed1 != edEnd) {
1088-
ed1->copy(buf.data(0), pHead->byteOrder());
1088+
ed1->copy(buf.data(), pHead->byteOrder());
10891089
pos += ed1->size();
10901090
}
10911091
if (ed2 != edEnd) {
@@ -1187,7 +1187,7 @@ namespace Exiv2 {
11871187
buf.clear();
11881188
if (cc) buf.copyBytes(8, cc->pData() + 8, cc->size() - 8);
11891189
if (edX != edEnd && edX->size() == 4) {
1190-
edX->copy(buf.data(0), pHead->byteOrder());
1190+
edX->copy(buf.data(), pHead->byteOrder());
11911191
}
11921192
if (edY != edEnd && edY->size() == 4) {
11931193
edY->copy(buf.data(4), pHead->byteOrder());

0 commit comments

Comments
 (0)