Fix a bug reported by cppcheck and an OOB access, kudos to Floessie

This commit is contained in:
heckflosse 2016-07-08 12:41:38 +02:00
parent c8779c04f5
commit b744eae46d

View File

@ -121,33 +121,49 @@ void ImageData::extractInfo ()
return; return;
} }
make = "";
model = "";
serial = "";
orientation = "";
expcomp = 0;
shutter = 0;
aperture = 0;
focal_len = focal_len35mm = 0;
focus_dist = 0;
iso_speed = 0;
memset(&time, 0, sizeof(time)); memset(&time, 0, sizeof(time));
timeStamp = 0; timeStamp = 0;
iso_speed = 0;
aperture = 0.0;
focal_len = 0.0;
focal_len35mm = 0.0;
focus_dist = 0.0f;
shutter = 0.0;
expcomp = 0.0;
make.clear();
model.clear();
serial.clear();
orientation.clear();
lens.clear();
if (root->getTag("Make")) { if (root->getTag("Make")) {
make = root->getTag ("Make")->valueToString(); make = root->getTag ("Make")->valueToString();
// same dcraw treatment // Same dcraw treatment
static const char *corp[] = { for (const auto& corp : {
"Canon", "NIKON", "EPSON", "KODAK", "Kodak", "OLYMPUS", "PENTAX", "RICOH", "Canon",
"MINOLTA", "Minolta", "Konica", "CASIO", "Sinar", "Phase One", "NIKON",
"SAMSUNG", "Mamiya", "MOTOROLA", "Leaf" "EPSON",
}; "KODAK",
"Kodak",
for (size_t i = 0; i < (sizeof(corp) / sizeof(*corp)); i++) "OLYMPUS",
if ( make.find( corp[i] ) != std::string::npos ) { /* Simplify company names */ "PENTAX",
make = corp[i]; "RICOH",
"MINOLTA",
"Minolta",
"Konica",
"CASIO",
"Sinar",
"Phase One",
"SAMSUNG",
"Mamiya",
"MOTOROLA",
"Leaf"
}) {
if (make.find(corp) != std::string::npos) { // Simplify company names
make = corp;
break; break;
} }
}
make.erase(make.find_last_not_of(' ') + 1); make.erase(make.find_last_not_of(' ') + 1);
} }
@ -156,24 +172,27 @@ void ImageData::extractInfo ()
model = root->getTag("Model")->valueToString(); model = root->getTag("Model")->valueToString();
} }
if (!(model.size() == 0)) { if (!model.empty()) {
std::size_t i = 0; std::string::size_type i = 0;
if ( make.find("KODAK") != std::string::npos ) { if (
if( (i = model.find(" DIGITAL CAMERA")) != std::string::npos || make.find("KODAK") != std::string::npos
(i = model.find(" Digital Camera")) != std::string::npos || && (
(i = model.find("FILE VERSION")) ) { (i = model.find(" DIGITAL CAMERA")) != std::string::npos
|| (i = model.find(" Digital Camera")) != std::string::npos
|| (i = model.find("FILE VERSION")) != std::string::npos
)
) {
model.resize(i); model.resize(i);
} }
}
model.erase(model.find_last_not_of(' ') + 1); model.erase(model.find_last_not_of(' ') + 1);
//if( (i=model.find( make )) != std::string::npos ) if (!strncasecmp(model.c_str(), make.c_str(), make.size())) {
if( !strncasecmp (model.c_str(), make.c_str(), make.size()) ) if (model.size() >= make.size() && model[make.size()] == ' ') {
if( model.at( make.size() ) == ' ') {
model.erase(0, make.size() + 1); model.erase(0, make.size() + 1);
} }
}
if (model.find( "Digital Camera ") != std::string::npos) { if (model.find( "Digital Camera ") != std::string::npos) {
model.erase(0, 15); model.erase(0, 15);