clang-tidy: use auto

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 3 years ago
parent 962e3b7369
commit 04bacdedd6

@ -932,7 +932,7 @@ namespace Action {
const Params::PreviewNumbers& numbers = Params::instance().previewNumbers_;
for (auto number : numbers) {
size_t num = static_cast<size_t>(number);
auto num = static_cast<size_t>(number);
if (num == 0) {
// Write all previews
for (num = 0; num < pvList.size(); ++num) {

@ -150,7 +150,7 @@ int main(int argc, char* const argv[])
assert(task);
// Process all files
int s = static_cast<int>(params.files_.size());
auto s = static_cast<int>(params.files_.size());
if (params.action_ & Action::extract && params.target_ & Params::ctStdInOut && s > 1) {
std::cerr << params.progname() << ": " << _("Only one file is allowed when extracting to stdout") << std::endl;
rc = 1;
@ -949,7 +949,7 @@ static int readFileToBuf(FILE* f,Exiv2::DataBuf& buf)
bool more {true};
while ( more ) {
char buff[buff_size];
int n = static_cast<int>(fread(buff, 1, buff_size, f));
auto n = static_cast<int>(fread(buff, 1, buff_size, f));
more = n > 0 ;
if ( more ) {
bytes.resize(nBytes+n);
@ -1270,7 +1270,7 @@ namespace {
}
if (k > i) {
bool ok = false;
int num = Exiv2::stringTo<int>(os.str(), ok);
auto num = Exiv2::stringTo<int>(os.str(), ok);
if (ok && num >= 0) {
previewNumbers.insert(num);
}
@ -1282,7 +1282,7 @@ namespace {
}
if (!(k < optArg.size() && optArg[i] == ',')) break;
}
int ret = static_cast<int>(k - j);
auto ret = static_cast<int>(k - j);
if (ret == 0) {
previewNumbers.insert(0);
}

@ -308,7 +308,7 @@ int main(int argc, char* const argv[])
if ( option == 'a' || option == 'i' ) {
Exiv2::IptcData &iptcData = image->iptcData();
for (Exiv2::IptcData::const_iterator i = iptcData.begin(); i != iptcData.end(); ++i) {
for (auto i = iptcData.begin(); i != iptcData.end(); ++i) {
std::string name ;
Jzon::Node& object = objectForKey(i->key(),root,name);
push(object,name,i);

@ -247,13 +247,13 @@ std::string Position::toExifString(double d,bool bRational,bool bLat)
const char* EW = d>=0.0?"E":"W";
const char* NSEW = bLat ? NS: EW;
if ( d < 0 ) d = -d;
int deg = static_cast<int>(d);
auto deg = static_cast<int>(d);
d -= deg;
d *= 60;
int min = static_cast<int>(d);
auto min = static_cast<int>(d);
d -= min;
d *= 60;
int sec = static_cast<int>(d);
auto sec = static_cast<int>(d);
char result[200];
if ( bRational )
snprintf(result,sizeof(result),"%d/1 %d/1 %d/1" ,deg,min,sec);

@ -114,7 +114,7 @@ int main(int argc, char** const argv)
do {
n = ::getopt(argc,argv,::optstring);
if ( n >= 0 ) {
char N = static_cast<char>(n);
auto N = static_cast<char>(n);
std::cout << n << " = " << N;
} else {
std::cout << n ;
@ -132,7 +132,7 @@ int main(int argc, char** const argv)
do {
n = Util::getopt(argc,argv,::optstring);
if ( n >= 0 ) {
char N = static_cast<char>(n);
auto N = static_cast<char>(n);
std::cout << n << " = " << N;
} else {
std::cout << n ;

@ -189,7 +189,7 @@ int WriteReadSeek(BasicIo &io)
std::cerr << ": WRS size is not " << size1 << "\n";
return 2;
}
long backup = static_cast<long>(size1);
auto backup = static_cast<long>(size1);
io.seek(-backup, BasicIo::cur);
int c = EOF;

@ -47,7 +47,7 @@ try {
}
// Map it to memory
const Exiv2::byte* pData = file.mmap();
long size = static_cast<long>(file.size());
auto size = static_cast<long>(file.size());
DataBuf buf(size);
// Read from the memory mapped region
buf.copyBytes(0, pData, buf.size());

@ -1263,7 +1263,7 @@ namespace Exiv2 {
}
// submit to the remote machine.
long dataSize = static_cast<long>(src.size() - left - right);
auto dataSize = static_cast<long>(src.size() - left - right);
if (dataSize > 0) {
auto data = static_cast<byte*>(std::malloc(dataSize));
src.seek(left, BasicIo::beg);

@ -217,7 +217,7 @@ namespace Exiv2
enforce(box_length >= hdrsize, Exiv2::kerCorruptedMetadata);
enforce(box_length - hdrsize <= static_cast<uint64_t>(pbox_end - restore), Exiv2::kerCorruptedMetadata);
const size_t buffer_size = static_cast<size_t>(box_length - hdrsize);
const auto buffer_size = static_cast<size_t>(box_length - hdrsize);
if (skipBox(box_type)) {
if (bTrace) {
out << std::endl;
@ -637,7 +637,7 @@ namespace Exiv2
xmpID_ = unknownID_;
long address = 0;
const long file_end = static_cast<long>(io_->size());
const auto file_end = static_cast<long>(io_->size());
while (address < file_end) {
io_->seek(address, BasicIo::beg);
address = boxHandler(std::cout,kpsNone,file_end,0);
@ -671,7 +671,7 @@ namespace Exiv2
IoCloser closer(*io_);
long address = 0;
const long file_end = static_cast<long>(io_->size());
const auto file_end = static_cast<long>(io_->size());
while (address < file_end) {
io_->seek(address, BasicIo::beg);
address = boxHandler(out,option,file_end,depth);

@ -2730,8 +2730,8 @@ namespace Exiv2::Internal {
return os;
}
int const exifFlMin = static_cast<int>(static_cast<float>(pos->value().toInt64(1)) / pos->value().toFloat(2));
int const exifFlMax = static_cast<int>(static_cast<float>(pos->value().toInt64(0)) / pos->value().toFloat(2));
auto const exifFlMin = static_cast<int>(static_cast<float>(pos->value().toInt64(1)) / pos->value().toFloat(2));
auto const exifFlMax = static_cast<int>(static_cast<float>(pos->value().toInt64(0)) / pos->value().toFloat(2));
ExifKey aperKey("Exif.CanonCs.MaxAperture");
pos = metadata->findKey(aperKey);
@ -2894,7 +2894,7 @@ namespace Exiv2::Internal {
// see also printSi0x0017
std::ostringstream oss;
oss.copyfmt(os);
int res = static_cast<int>(100.0 * (static_cast<short>(value.toInt64()) / 32.0 + 5.0) + 0.5);
auto res = static_cast<int>(100.0 * (static_cast<short>(value.toInt64()) / 32.0 + 5.0) + 0.5);
os << std::fixed << std::setprecision(2) << res / 100.0;
os.copyfmt(oss);
}
@ -3067,7 +3067,7 @@ namespace Exiv2::Internal {
// remove fraction
const auto remainder = val & 0x1f;
val -= remainder;
float frac = static_cast<float>(remainder);
auto frac = static_cast<float>(remainder);
// convert 1/3 (0x0c) and 2/3 (0x14) codes
if (frac == 0x0c) {
frac = 32.0F / 3;

@ -527,7 +527,7 @@ namespace Exiv2::Internal {
std::vector<char> numbers;
for(size_t i=0; i<value.size(); i++)
{
const char l = static_cast<char>(value.toInt64(i));
const auto l = static_cast<char>(value.toInt64(i));
if(l!=0)
{
numbers.push_back(l);

@ -774,7 +774,7 @@ namespace Exiv2 {
deg[i] = static_cast<double>(z)/d;
}
double min = deg[0] * 60.0 + deg[1] + deg[2] / 60.0;
int ideg = static_cast<int>(min / 60.0);
auto ideg = static_cast<int>(min / 60.0);
min -= ideg * 60;
std::ostringstream oss;
oss << ideg << ","

@ -816,7 +816,7 @@ namespace Exiv2::Internal {
const uint32_t component_size = ciffComponent.size();
enforce(component_size % 2 == 0, kerCorruptedMetadata);
enforce(component_size/2 <= static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()), kerCorruptedMetadata);
const uint16_t num_components = static_cast<uint16_t>(component_size/2);
const auto num_components = static_cast<uint16_t>(component_size / 2);
uint16_t c = 1;
while (c < num_components) {
uint16_t n = 1;

@ -227,7 +227,7 @@ int Exiv2::http(Exiv2::Dictionary& request,Exiv2::Dictionary& response,std::stri
////////////////////////////////////
// open the socket
int sockfd = static_cast<int>(socket(AF_INET , SOCK_STREAM,IPPROTO_TCP));
auto sockfd = static_cast<int>(socket(AF_INET, SOCK_STREAM, IPPROTO_TCP));
if (sockfd < 0)
return error(errors, "unable to create socket\n", nullptr, nullptr, 0);

@ -386,7 +386,7 @@ namespace Exiv2 {
// Overflow check
enforce(allocate64 <= static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()), kerCorruptedMetadata);
enforce(allocate64 <= static_cast<uint64_t>(std::numeric_limits<long>::max()), kerCorruptedMetadata);
const long allocate = static_cast<long>(allocate64);
const auto allocate = static_cast<long>(allocate64);
DataBuf buf(allocate); // allocate a buffer
buf.copyBytes(0, dir.c_data(8), 4); // copy dir[8:11] into buffer (short strings)
@ -517,7 +517,7 @@ namespace Exiv2 {
// read header (we already know for certain that we have a Tiff file)
io.readOrThrow(dir.data(), 8, kerCorruptedMetadata);
char c = static_cast<char>(dir.read_uint8(0));
auto c = static_cast<char>(dir.read_uint8(0));
bool bSwap = ( c == 'M' && isLittleEndianPlatform() )
|| ( c == 'I' && isBigEndianPlatform() )
;

@ -398,8 +398,8 @@ namespace Exiv2 {
foundIccData = true ;
--search ;
}
int chunk = static_cast<int>(buf.read_uint8(2 + 12));
int chunks = static_cast<int>(buf.read_uint8(2 + 13));
auto chunk = static_cast<int>(buf.read_uint8(2 + 12));
auto chunks = static_cast<int>(buf.read_uint8(2 + 13));
// ICC1v43_2010-12.pdf header is 14 bytes
// header = "ICC_PROFILE\0" (12 bytes)
// chunk/chunks are a single byte
@ -1082,7 +1082,7 @@ namespace Exiv2 {
if (chunkSize > maxChunkSize) {
chunkSize = maxChunkSize;
// Don't break at a valid IRB boundary
const long writtenSize = static_cast<long>(chunkStart - newPsData.c_data());
const auto writtenSize = static_cast<long>(chunkStart - newPsData.c_data());
if (Photoshop::valid(newPsData.c_data(), writtenSize + chunkSize)) {
// Since an IRB has minimum size 12,
// (chunkSize - 8) can't be also a IRB boundary

@ -2623,7 +2623,7 @@ fmountlens[] = {
*/
if (metadata == nullptr)
{
const unsigned char vid = static_cast<unsigned char>(value.toInt64(0));
const auto vid = static_cast<unsigned char>(value.toInt64(0));
/* the 'FMntLens' name is added to the anonymous struct for
* fmountlens[]

@ -1361,9 +1361,9 @@ namespace Exiv2::Internal {
return os << value;
}
byte v0 = static_cast<byte>(value.toInt64(0));
byte v2 = static_cast<byte>(value.toInt64(2));
byte v3 = static_cast<byte>(value.toInt64(3));
auto v0 = static_cast<byte>(value.toInt64(0));
auto v2 = static_cast<byte>(value.toInt64(2));
auto v3 = static_cast<byte>(value.toInt64(3));
for (auto&& type : lensTypes) {
if (type.val[0] == v0 && type.val[1] == v2 && type.val[2] == v3) {
@ -1407,8 +1407,8 @@ namespace Exiv2::Internal {
return os << value;
}
byte v0 = static_cast<byte>(value.toInt64(0));
byte v2 = static_cast<byte>(value.toInt64(2));
auto v0 = static_cast<byte>(value.toInt64(0));
auto v2 = static_cast<byte>(value.toInt64(2));
for (auto&& model : extenderModels) {
if (model.val[0] == v0 && model.val[1] == v2) {

@ -672,14 +672,14 @@ namespace Exiv2::Internal {
std::ostream& PanasonicMakerNote::printAccelerometer(std::ostream& os, const Value& value, const ExifData*)
{
// value is stored as unsigned int, but should be read as int16_t.
const int16_t i = static_cast<int16_t>(value.toInt64());
const auto i = static_cast<int16_t>(value.toInt64());
return os << i;
} // PanasonicMakerNote::printAccelerometer
std::ostream& PanasonicMakerNote::printRollAngle(std::ostream& os, const Value& value, const ExifData*)
{
// value is stored as unsigned int, but should be read as int16_t.
const int16_t i = static_cast<int16_t>(value.toInt64());
const auto i = static_cast<int16_t>(value.toInt64());
std::ostringstream oss;
oss.copyfmt(os);
os << std::fixed << std::setprecision(1) << i / 10.0;
@ -691,7 +691,7 @@ namespace Exiv2::Internal {
std::ostream& PanasonicMakerNote::printPitchAngle(std::ostream& os, const Value& value, const ExifData*)
{
// value is stored as unsigned int, but should be read as int16_t.
const int16_t i = static_cast<int16_t>(value.toInt64());
const auto i = static_cast<int16_t>(value.toInt64());
std::ostringstream oss;
oss.copyfmt(os);
os << std::fixed << std::setprecision(1) << -i / 10.0;

@ -181,7 +181,7 @@ namespace Exiv2 {
img->setIptcData(iptcData_);
img->setXmpData(xmpData_);
img->writeMetadata();
long imgSize = static_cast<long>(img->io().size());
auto imgSize = static_cast<long>(img->io().size());
DataBuf imgBuf = img->io().read(imgSize);
#ifdef EXIV2_DEBUG_MESSAGES
@ -257,7 +257,7 @@ namespace Exiv2 {
if (bufRead != buffer.size())
throw Error(kerInputDataReadFailed);
int headerSize = static_cast<int>(byteSwap_(buffer, 0, bSwap_));
auto headerSize = static_cast<int>(byteSwap_(buffer, 0, bSwap_));
if (headerSize <= 0 ) throw Error(kerNoImageInInputData);
#ifdef EXIV2_DEBUG_MESSAGES

@ -158,7 +158,7 @@ namespace Exiv2::Internal {
Exiv2::kerCorruptedMetadata);
const byte* text = data.c_data(keysize + 3 + languageTextSize + 1 + translatedKeyTextSize + 1);
const long textsize = static_cast<long>(
const auto textsize = static_cast<long>(
data.size() - (keysize + 3 + languageTextSize + 1 + translatedKeyTextSize + 1));
if (compressionFlag == 0x00) {

@ -313,7 +313,7 @@ namespace Exiv2 {
1; // leading string length
enforce(name_l < dataOffset, kerCorruptedMetadata);
uint32_t start = static_cast<uint32_t>(name_l);
auto start = static_cast<uint32_t>(name_l);
bool bLF = false;
// decode the chunk

@ -301,8 +301,8 @@ namespace Exiv2 {
kerCorruptedMetadata);
#endif
long jpg_img_off = static_cast<long>(jpg_img_off_u32);
long jpg_img_len = static_cast<long>(jpg_img_len_u32);
auto jpg_img_off = static_cast<long>(jpg_img_off_u32);
auto jpg_img_len = static_cast<long>(jpg_img_len_u32);
enforce(jpg_img_len >= 12, kerCorruptedMetadata);

@ -2784,9 +2784,9 @@ namespace Exiv2::Internal {
if (fraction != 0) p = 1;
const double ss = std::fmod(t, 60);
const double minutes = (t - ss)/60;
const int mm = static_cast<int>(std::fmod(minutes, 60));
const auto mm = static_cast<int>(std::fmod(minutes, 60));
const double hours = (minutes - mm)/60;
const int hh = static_cast<int>(std::fmod(hours, 24));
const auto hh = static_cast<int>(std::fmod(hours, 24));
os << std::setw(2) << std::setfill('0') << std::right << hh << ":"
<< std::setw(2) << std::setfill('0') << std::right << mm << ":"

@ -1077,7 +1077,7 @@ namespace Exiv2::Internal {
}
// Also add the size of data, but only if needed
if (isRootDir) {
uint32_t sd = static_cast<uint32_t>(component->sizeData());
auto sd = static_cast<uint32_t>(component->sizeData());
sd += sd & 1; // Align data to word boundary
sizeData += sd;
}
@ -1104,7 +1104,7 @@ namespace Exiv2::Internal {
sv += sv & 1; // Align value to word boundary
valueIdx += sv;
}
uint32_t sd = static_cast<uint32_t>(component->sizeData());
auto sd = static_cast<uint32_t>(component->sizeData());
sd += sd & 1; // Align data to word boundary
dataIdx += sd;
}
@ -1134,7 +1134,7 @@ namespace Exiv2::Internal {
idx += sv;
valueIdx += sv;
}
uint32_t sd = static_cast<uint32_t>(component->sizeData());
auto sd = static_cast<uint32_t>(component->sizeData());
sd += sd & 1; // Align data to word boundary
dataIdx += sd;
}
@ -1626,7 +1626,7 @@ namespace Exiv2::Internal {
sv += sv & 1; // Align value to word boundary
len += sv;
}
uint32_t sd = static_cast<uint32_t>(component->sizeData());
auto sd = static_cast<uint32_t>(component->sizeData());
sd += sd & 1; // Align data to word boundary
len += sd;
}

@ -1521,7 +1521,7 @@ namespace Exiv2::Internal {
if (count > std::numeric_limits<uint32_t>::max() / typeSize) {
throw Error(kerArithmeticOverflow);
}
uint32_t size = static_cast<uint32_t>(typeSize * count);
auto size = static_cast<uint32_t>(typeSize * count);
uint32_t offset = getLong(p, byteOrder());
byte* pData = p;
if ( size > 4

@ -628,13 +628,13 @@ namespace Exiv2 {
int64_t parseInt64(const std::string& s, bool& ok)
{
int64_t ret = stringTo<int64_t>(s, ok);
auto ret = stringTo<int64_t>(s, ok);
if (ok) return ret;
auto f = stringTo<float>(s, ok);
if (ok) return static_cast<int64_t>(f);
Rational r = stringTo<Rational>(s, ok);
auto r = stringTo<Rational>(s, ok);
if (ok) {
if (r.second <= 0) {
ok = false;
@ -664,7 +664,7 @@ namespace Exiv2 {
auto ret = stringTo<float>(s, ok);
if (ok) return ret;
Rational r = stringTo<Rational>(s, ok);
auto r = stringTo<Rational>(s, ok);
if (ok) {
if (r.second == 0) {
ok = false;
@ -683,10 +683,10 @@ namespace Exiv2 {
Rational parseRational(const std::string& s, bool& ok)
{
Rational ret = stringTo<Rational>(s, ok);
auto ret = stringTo<Rational>(s, ok);
if (ok) return ret;
long l = stringTo<long>(s, ok);
auto l = stringTo<long>(s, ok);
if (ok)
return {l, 1};
@ -714,7 +714,7 @@ namespace Exiv2 {
}
// Beware: primitive conversion algorithm
int32_t den = 1000000;
const long d_as_long = static_cast<long>(d);
const auto d_as_long = static_cast<long>(d);
if (Safe::abs(d_as_long) > 2147) {
den = 10000;
}

@ -1001,7 +1001,7 @@ namespace Exiv2 {
tms.tm_mday = date_.day;
tms.tm_mon = date_.month - 1;
tms.tm_year = date_.year - 1900;
int64_t l = static_cast<int64_t>(std::mktime(&tms));
auto l = static_cast<int64_t>(std::mktime(&tms));
ok_ = (l != -1);
return l;
}

@ -208,7 +208,7 @@ namespace Exiv2 {
// Check that `size_u32` is safe to cast to `long`.
enforce(size_u32 <= static_cast<size_t>(std::numeric_limits<unsigned int>::max()),
Exiv2::kerCorruptedMetadata);
const long size = static_cast<long>(size_u32);
const auto size = static_cast<long>(size_u32);
DataBuf payload(size);
io_->readOrThrow(payload.data(), payload.size(), Exiv2::kerCorruptedMetadata);
if ( payload.size() % 2 ) {
@ -346,7 +346,7 @@ namespace Exiv2 {
// Check that `size_u32` is safe to cast to `long`.
enforce(size_u32 <= static_cast<size_t>(std::numeric_limits<unsigned int>::max()),
Exiv2::kerCorruptedMetadata);
const long size = static_cast<long>(size_u32);
const auto size = static_cast<long>(size_u32);
DataBuf payload(size);
io_->readOrThrow(payload.data(), size, Exiv2::kerCorruptedMetadata);
@ -572,7 +572,7 @@ namespace Exiv2 {
// Check that `size_u32` is safe to cast to `long`.
enforce(size_u32 <= static_cast<uint32_t>(std::numeric_limits<long>::max()), Exiv2::kerCorruptedMetadata);
const long size = static_cast<long>(size_u32);
const auto size = static_cast<long>(size_u32);
// Check that `size` is within bounds.
enforce(io_->tell() <= filesize, Exiv2::kerCorruptedMetadata);

Loading…
Cancel
Save