From 6f5032db37ed3c8c7c74e467dabe5f6dfad23d70 Mon Sep 17 00:00:00 2001 From: Andreas Huggel Date: Tue, 16 Dec 2008 17:59:07 +0000 Subject: [PATCH] Do not access the first element of an empty vector. --- src/crwimage.cpp | 2 +- src/exif.cpp | 2 +- src/jpgimage.cpp | 3 +-- src/preview.cpp | 2 +- src/tiffimage.cpp | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/crwimage.cpp b/src/crwimage.cpp index a91ecc5b..0c9e9fe5 100644 --- a/src/crwimage.cpp +++ b/src/crwimage.cpp @@ -164,7 +164,7 @@ namespace Exiv2 { // Write new buffer to file BasicIo::AutoPtr tempIo(io_->temporary()); // may throw assert(tempIo.get() != 0); - tempIo->write(&blob[0], static_cast(blob.size())); + tempIo->write((blob.size() > 0 ? &blob[0] : 0), static_cast(blob.size())); io_->close(); io_->transfer(*tempIo); // may throw diff --git a/src/exif.cpp b/src/exif.cpp index 7c449046..34f799d4 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -679,7 +679,7 @@ namespace { const Exiv2::IptcData emptyIptc; const Exiv2::XmpData emptyXmp; Exiv2::TiffParser::encode(blob, 0, 0, Exiv2::littleEndian, thumb, emptyIptc, emptyXmp); - return Exiv2::DataBuf(&blob[0], static_cast(blob.size())); + return Exiv2::DataBuf((blob.size() > 0 ? &blob[0] : 0), static_cast(blob.size())); } const char* JpegThumbnail::mimeType() const diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index 05a2a3fc..123569b2 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -616,9 +616,8 @@ namespace Exiv2 { const byte* pExifData = rawExif.pData_; uint32_t exifSize = rawExif.size_; if (wm == wmIntrusive) { + pExifData = blob.size() > 0 ? &blob[0] : 0; exifSize = static_cast(blob.size()); - // Extra check to prevent MSVC debug assertion - if (exifSize > 0) pExifData = &blob[0]; } if (exifSize > 0) { // Write APP1 marker, size of APP1 field, Exif id and Exif data diff --git a/src/preview.cpp b/src/preview.cpp index 17ac2845..bb178fb9 100644 --- a/src/preview.cpp +++ b/src/preview.cpp @@ -639,7 +639,7 @@ namespace { const IptcData emptyIptc; const XmpData emptyXmp; TiffParser::encode(blob, 0, 0, Exiv2::littleEndian, preview, emptyIptc, emptyXmp); - return DataBuf(&blob[0], static_cast(blob.size())); + return DataBuf((blob.size() > 0 ? &blob[0] : 0), static_cast(blob.size())); } } // namespace diff --git a/src/tiffimage.cpp b/src/tiffimage.cpp index 99e0bce6..e8a2ed6c 100644 --- a/src/tiffimage.cpp +++ b/src/tiffimage.cpp @@ -177,7 +177,7 @@ namespace Exiv2 { } else { // Size of the buffer changed, write from blob - tempIo->write(&blob[0], static_cast(blob.size())); + tempIo->write((blob.size() > 0 ? &blob[0] : 0), static_cast(blob.size())); } io_->close(); io_->transfer(*tempIo); // may throw