Do not access the first element of an empty vector.

This commit is contained in:
Andreas Huggel 2008-12-16 17:59:07 +00:00
parent a05687e159
commit 6f5032db37
5 changed files with 5 additions and 6 deletions

View File

@ -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<long>(blob.size()));
tempIo->write((blob.size() > 0 ? &blob[0] : 0), static_cast<long>(blob.size()));
io_->close();
io_->transfer(*tempIo); // may throw

View File

@ -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<long>(blob.size()));
return Exiv2::DataBuf((blob.size() > 0 ? &blob[0] : 0), static_cast<long>(blob.size()));
}
const char* JpegThumbnail::mimeType() const

View File

@ -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<uint32_t>(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

View File

@ -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<long>(blob.size()));
return DataBuf((blob.size() > 0 ? &blob[0] : 0), static_cast<long>(blob.size()));
}
} // namespace

View File

@ -177,7 +177,7 @@ namespace Exiv2 {
}
else {
// Size of the buffer changed, write from blob
tempIo->write(&blob[0], static_cast<long>(blob.size()));
tempIo->write((blob.size() > 0 ? &blob[0] : 0), static_cast<long>(blob.size()));
}
io_->close();
io_->transfer(*tempIo); // may throw