Skip to content

Commit b4c90b5

Browse files
committed
clang-tidy: replace pointer magic with data()
Signed-off-by: Rosen Penev <[email protected]>
1 parent 93dc63b commit b4c90b5

File tree

12 files changed

+18
-18
lines changed

12 files changed

+18
-18
lines changed

samples/tiff-test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void mini1(const char* path) {
6161
enforce(wm == wmIntrusive, Exiv2::ErrorCode::kerErrorMessage, "encode returned an unexpected value");
6262
std::cout << "Test 3: Wrote non-empty Exif data without original binary data:\n";
6363
exifData.clear();
64-
ByteOrder bo = ExifParser::decode(exifData, &blob[0], blob.size());
64+
ByteOrder bo = ExifParser::decode(exifData, blob.data(), blob.size());
6565
enforce(bo == bigEndian, Exiv2::ErrorCode::kerErrorMessage, "decode returned an unexpected value");
6666
print(exifData);
6767
}

src/crwimage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void CrwImage::writeMetadata() {
9393

9494
// Write new buffer to file
9595
MemIo tempIo;
96-
tempIo.write((!blob.empty() ? &blob[0] : nullptr), blob.size());
96+
tempIo.write((!blob.empty() ? blob.data() : nullptr), blob.size());
9797
io_->close();
9898
io_->transfer(tempIo); // may throw
9999

src/image.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,10 @@ void Image::printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStruct
425425
io.seekOrThrow(offset, BasicIo::beg, ErrorCode::kerCorruptedMetadata); // position
426426
std::vector<byte> bytes(count); // allocate memory
427427
// TODO: once we have C++11 use bytes.data()
428-
io.readOrThrow(&bytes[0], count, ErrorCode::kerCorruptedMetadata);
428+
io.readOrThrow(bytes.data(), count, ErrorCode::kerCorruptedMetadata);
429429
io.seekOrThrow(restore, BasicIo::beg, ErrorCode::kerCorruptedMetadata);
430430
// TODO: once we have C++11 use bytes.data()
431-
IptcData::printStructure(out, makeSliceUntil(&bytes[0], count), depth);
431+
IptcData::printStructure(out, makeSliceUntil(bytes.data(), count), depth);
432432
}
433433
} else if (option == kpsRecursive && tag == 0x927c /* MakerNote */ && count > 10) {
434434
const long restore = io.tell(); // save

src/image_int.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ std::string stringFormat(const char* format, ...) {
2424
buffer.resize(need + 1);
2525
va_list args; // variable arg list
2626
va_start(args, format); // args start after format
27-
rc = vsnprintf(&buffer[0], buffer.size(), format, args);
27+
rc = vsnprintf(buffer.data(), buffer.size(), format, args);
2828
va_end(args); // free the args
2929
if (rc > 0)
3030
need = static_cast<size_t>(rc);
3131
} while (buffer.size() <= need);
3232

3333
if (rc > 0)
34-
result = std::string(&buffer[0], need);
34+
result = std::string(buffer.data(), need);
3535
return result;
3636
}
3737

src/jpgimage.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void JpegBase::readMetadata() {
188188
append(psBlob, buf.c_data(16), size - 16);
189189
}
190190
// Check whether psBlob is complete
191-
if (!psBlob.empty() && Photoshop::valid(&psBlob[0], psBlob.size())) {
191+
if (!psBlob.empty() && Photoshop::valid(psBlob.data(), psBlob.size())) {
192192
--search;
193193
foundCompletePsData = true;
194194
}
@@ -263,7 +263,7 @@ void JpegBase::readMetadata() {
263263
const byte* record = nullptr;
264264
uint32_t sizeIptc = 0;
265265
uint32_t sizeHdr = 0;
266-
const byte* pCur = &psBlob[0];
266+
const byte* pCur = psBlob.data();
267267
const byte* pEnd = pCur + psBlob.size();
268268
while (pCur < pEnd && 0 == Photoshop::locateIptcIrb(pCur, pEnd - pCur, &record, sizeHdr, sizeIptc)) {
269269
#ifdef EXIV2_DEBUG_MESSAGES
@@ -274,7 +274,7 @@ void JpegBase::readMetadata() {
274274
}
275275
pCur = record + sizeHdr + sizeIptc + (sizeIptc & 1);
276276
}
277-
if (!iptcBlob.empty() && IptcParser::decode(iptcData_, &iptcBlob[0], iptcBlob.size())) {
277+
if (!iptcBlob.empty() && IptcParser::decode(iptcData_, iptcBlob.data(), iptcBlob.size())) {
278278
#ifndef SUPPRESS_WARNINGS
279279
EXV_WARNING << "Failed to decode IPTC metadata.\n";
280280
#endif
@@ -680,7 +680,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) {
680680
// Append to psBlob
681681
append(psBlob, buf.c_data(16), buf.size() - 16);
682682
// Check whether psBlob is complete
683-
if (!psBlob.empty() && Photoshop::valid(&psBlob[0], psBlob.size())) {
683+
if (!psBlob.empty() && Photoshop::valid(psBlob.data(), psBlob.size())) {
684684
foundCompletePsData = true;
685685
}
686686
} else if (marker == com_ && skipCom == notfound) {
@@ -750,7 +750,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) {
750750
size_t exifSize = rawExif.size();
751751
WriteMethod wm = ExifParser::encode(blob, pExifData, exifSize, bo, exifData_);
752752
if (wm == wmIntrusive) {
753-
pExifData = !blob.empty() ? &blob[0] : nullptr;
753+
pExifData = !blob.empty() ? blob.data() : nullptr;
754754
exifSize = blob.size();
755755
}
756756
if (exifSize > 0) {

src/photoshop.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ DataBuf Photoshop::setIptcIrb(const byte* pPsData, size_t sizePsData, const Iptc
170170

171171
// Data is rounded to be even
172172
if (!psBlob.empty())
173-
rc = DataBuf(&psBlob[0], psBlob.size());
173+
rc = DataBuf(psBlob.data(), psBlob.size());
174174
#ifdef EXIV2_DEBUG_MESSAGES
175175
std::cerr << "IRB block at the end of Photoshop::setIptcIrb\n";
176176
if (rc.empty())

src/pngchunk_int.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void PngChunk::parseChunkContent(Image* pImage, const byte* key, size_t keySize,
246246
pCur = record + sizeHdr + sizeIptc;
247247
pCur += (sizeIptc & 1);
248248
}
249-
if (!iptcBlob.empty() && IptcParser::decode(pImage->iptcData(), &iptcBlob[0], iptcBlob.size())) {
249+
if (!iptcBlob.empty() && IptcParser::decode(pImage->iptcData(), iptcBlob.data(), iptcBlob.size())) {
250250
#ifndef SUPPRESS_WARNINGS
251251
EXV_WARNING << "Failed to decode IPTC metadata.\n";
252252
#endif

src/pngimage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ void PngImage::doWriteMetadata(BasicIo& outIo) {
572572
if (!blob.empty()) {
573573
static const char exifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00};
574574
std::string rawExif =
575-
std::string(exifHeader, 6) + std::string(reinterpret_cast<const char*>(&blob[0]), blob.size());
575+
std::string(exifHeader, 6) + std::string(reinterpret_cast<const char*>(blob.data()), blob.size());
576576
std::string chunk = PngChunk::makeMetadataChunk(rawExif, mdExif);
577577
if (outIo.write(reinterpret_cast<const byte*>(chunk.data()), chunk.size()) != chunk.size()) {
578578
throw Error(ErrorCode::kerImageWriteFailed);

src/psdimage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ uint32_t PsdImage::writeExifData(const ExifData& exifData, BasicIo& out) {
610610
if (out.write(buf, 4) != 4)
611611
throw Error(ErrorCode::kerImageWriteFailed);
612612
// Write encoded Exif data
613-
if (out.write(&blob[0], blob.size()) != blob.size())
613+
if (out.write(blob.data(), blob.size()) != blob.size())
614614
throw Error(ErrorCode::kerImageWriteFailed);
615615
resLength += static_cast<long>(blob.size()) + 12;
616616
if (blob.size() & 1) // even padding

src/tiffvisitor_int.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ void TiffEncoder::encodeXmp() {
557557
if (!xmpPacket.empty()) {
558558
// Set the XMP Exif tag to the new value
559559
auto value = Value::create(unsignedByte);
560-
value->read(reinterpret_cast<const byte*>(&xmpPacket[0]), xmpPacket.size(), invalidByteOrder);
560+
value->read(reinterpret_cast<const byte*>(xmpPacket.data()), xmpPacket.size(), invalidByteOrder);
561561
Exifdatum xmpDatum(xmpKey, value.get());
562562
exifData_.add(xmpDatum);
563563
}

0 commit comments

Comments
 (0)