Skip to content

Commit

Permalink
clang-tidy: use auto
Browse files Browse the repository at this point in the history
Found with modernize-use-auto

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb authored and piponazo committed May 17, 2021
1 parent 20dfab8 commit b871218
Show file tree
Hide file tree
Showing 41 changed files with 167 additions and 170 deletions.
2 changes: 1 addition & 1 deletion samples/Jzon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ namespace Jzon
void Array::Remove(size_t index)
{
if (index < children.size()) {
ChildList::iterator it = children.begin() + index;
auto it = children.begin() + index;
delete (*it);
children.erase(it);
}
Expand Down
2 changes: 1 addition & 1 deletion samples/addmoddel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ try {
// Get a pointer to a copy of the value
v = pos->getValue();
// Downcast the Value pointer to its actual type
Exiv2::URationalValue* prv = dynamic_cast<Exiv2::URationalValue*>(v.release());
auto prv = dynamic_cast<Exiv2::URationalValue*>(v.release());
if (prv == 0) throw Exiv2::Error(Exiv2::kerErrorMessage, "Downcast failed");
rv = Exiv2::URationalValue::UniquePtr(prv);
// Modify the value directly through the interface of URationalValue
Expand Down
4 changes: 2 additions & 2 deletions samples/exiv2json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void push(Jzon::Node& node,const std::string& key,T i)
case Exiv2::langAlt: {
ABORT_IF_I_EMTPY
Jzon::Object l ;
const Exiv2::LangAltValue& langs = dynamic_cast<const Exiv2::LangAltValue&>(i->value());
const auto& langs = dynamic_cast<const Exiv2::LangAltValue&>(i->value());
for (auto&& lang : langs.value_) {
l.Add(lang.first, lang.second);
}
Expand Down Expand Up @@ -246,7 +246,7 @@ void push(Jzon::Node& node,const std::string& key,T i)

void fileSystemPush(const char* path,Jzon::Node& nfs)
{
Jzon::Object& fs = (Jzon::Object&) nfs;
auto& fs = (Jzon::Object&)nfs;
fs.Add("path",path);
char resolved_path[2000]; // PATH_MAX];
fs.Add("realpath",realpath(path,resolved_path));
Expand Down
6 changes: 3 additions & 3 deletions samples/geotag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class UserData
// XML Parser Callbacks
static void startElement(void* userData, const char* name, const char** atts )
{
UserData* me = (UserData*) userData;
auto me = (UserData*)userData;
//for ( int i = 0 ; i < me->indent ; i++ ) printf(" ");
//printf("begin %s\n",name);
me->bTime = strcmp(name,"time")==0;
Expand All @@ -357,7 +357,7 @@ static void startElement(void* userData, const char* name, const char** atts )

static void endElement(void* userData, const char* name)
{
UserData* me = (UserData*) userData;
auto me = (UserData*)userData;
me->indent-- ;
if ( strcmp(name,"trkpt")==0 ) {

Expand All @@ -379,7 +379,7 @@ static void endElement(void* userData, const char* name)

void charHandler(void* userData,const char* s,int len)
{
UserData* me = (UserData*) userData;
auto me = (UserData*)userData;

if ( me->nTrkpt == 1 ) {
char buffer[100];
Expand Down
4 changes: 2 additions & 2 deletions samples/iptctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void processRemove(const std::string& line, int num, IptcData &iptcData)
const std::string key( line.substr(keyStart) );
IptcKey iptcKey(key);

IptcData::iterator iter = iptcData.findKey(iptcKey);
auto iter = iptcData.findKey(iptcKey);
if (iter != iptcData.end()) {
iptcData.erase(iter);
}
Expand Down Expand Up @@ -174,7 +174,7 @@ void processModify(const std::string& line, int num, IptcData &iptcData)
Value::UniquePtr value = Value::create(type);
value->read(data);

IptcData::iterator iter = iptcData.findKey(iptcKey);
auto iter = iptcData.findKey(iptcKey);
if (iter != iptcData.end()) {
iter->setValue(value.get());
}
Expand Down
2 changes: 1 addition & 1 deletion src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ namespace Action {
return 0;
}
Exiv2::Value::UniquePtr v = pos->getValue();
const Exiv2::CommentValue* pcv = dynamic_cast<const Exiv2::CommentValue*>(v.get());
const auto pcv = dynamic_cast<const Exiv2::CommentValue*>(v.get());
if (!pcv) {
if (Params::instance().verbose_) {
std::cout << _("Found Exif user comment with unexpected value type") << "\n";
Expand Down
22 changes: 11 additions & 11 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ namespace Exiv2 {
const bool wasOpen = (p_->fp_ != 0);
const std::string lastMode(p_->openMode_);

FileIo *fileIo = dynamic_cast<FileIo*>(&src);
auto fileIo = dynamic_cast<FileIo*>(&src);
if (fileIo) {
// Optimization if src is another instance of FileIo
fileIo->close();
Expand Down Expand Up @@ -1146,7 +1146,7 @@ namespace Exiv2 {
if (!isMalloced_) {
// Minimum size for 1st block
long size = EXV_MAX(blockSize * (1 + need / blockSize), size_);
byte* data = (byte*)std::malloc(size);
auto data = (byte*)std::malloc(size);
if ( data == NULL ) {
throw Error(kerMallocFailed);
}
Expand Down Expand Up @@ -1205,7 +1205,7 @@ namespace Exiv2 {

void MemIo::transfer(BasicIo& src)
{
MemIo *memIo = dynamic_cast<MemIo*>(&src);
auto memIo = dynamic_cast<MemIo*>(&src);
if (memIo) {
// Optimization if src is another instance of MemIo
if (p_->isMalloced_) {
Expand Down Expand Up @@ -1525,7 +1525,7 @@ namespace Exiv2 {
}

std::string data = orgPath.substr(base64Pos+7);
char* decodeData = new char[data.length()];
auto decodeData = new char[data.length()];
long size = base64decode(data.c_str(), decodeData, data.length());
if (size > 0) {
fs.write(decodeData, size);
Expand Down Expand Up @@ -1645,7 +1645,7 @@ namespace Exiv2 {
if (rcount == 0) {
throw Error(kerErrorMessage, "Data By Range is empty. Please check the permission.");
}
byte* source = (byte*)data.c_str();
auto source = (byte*)data.c_str();
size_t remain = rcount, totalRead = 0;
size_t iBlock = (rcount == size_) ? 0 : lowBlock;

Expand Down Expand Up @@ -1686,7 +1686,7 @@ namespace Exiv2 {
size_t nBlocks = (p_->size_ + p_->blockSize_ - 1) / p_->blockSize_;
p_->blocksMap_ = new BlockMap[nBlocks];
p_->isMalloced_ = true;
byte* source = (byte*)data.c_str();
auto source = (byte*)data.c_str();
size_t remain = p_->size_, iBlock = 0, totalRead = 0;
while (remain) {
size_t allow = EXV_MIN(remain, p_->blockSize_);
Expand Down Expand Up @@ -1746,7 +1746,7 @@ namespace Exiv2 {
size_t i = 0;
size_t readCount = 0;
size_t blockSize = 0;
byte* buf = (byte*) std::malloc(p_->blockSize_);
auto buf = (byte*)std::malloc(p_->blockSize_);
size_t nBlocks = (p_->size_ + p_->blockSize_ - 1) / p_->blockSize_;

// find $left
Expand Down Expand Up @@ -1796,7 +1796,7 @@ namespace Exiv2 {
// submit to the remote machine.
long dataSize = (long) (src.size() - left - right);
if (dataSize > 0) {
byte* data = (byte*) std::malloc(dataSize);
auto data = (byte*)std::malloc(dataSize);
src.seek(left, BasicIo::beg);
src.read(data, dataSize);
p_->writeRemote(data, (size_t)dataSize, (long)left, (long) (p_->size_ - right));
Expand Down Expand Up @@ -1830,7 +1830,7 @@ namespace Exiv2 {

// connect to the remote machine & populate the blocks just in time.
p_->populateBlocks(lowBlock, highBlock);
byte* fakeData = (byte*) std::calloc(p_->blockSize_, sizeof(byte));
auto fakeData = (byte*)std::calloc(p_->blockSize_, sizeof(byte));
if (!fakeData) {
throw Error(kerErrorMessage, "Unable to allocate data");
}
Expand Down Expand Up @@ -2127,7 +2127,7 @@ namespace Exiv2 {

// encode base64
size_t encodeLength = ((size + 2) / 3) * 4 + 1;
char* encodeData = new char[encodeLength];
auto encodeData = new char[encodeLength];
base64encode(data, size, encodeData, encodeLength);
// url encode
const std::string urlencodeData = urlencode(encodeData);
Expand Down Expand Up @@ -2348,7 +2348,7 @@ namespace Exiv2 {

// encode base64
size_t encodeLength = ((size + 2) / 3) * 4 + 1;
char* encodeData = new char[encodeLength];
auto encodeData = new char[encodeLength];
base64encode(data, size, encodeData, encodeLength);
// url encode
const std::string urlencodeData = urlencode(encodeData);
Expand Down
4 changes: 2 additions & 2 deletions src/bmffimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace Exiv2

std::string BmffImage::toAscii(long n)
{
const char* p = (const char*)&n;
const auto p = (const char*)&n;
std::string result;
for (int i = 0; i < 4; i++) {
char c = p[isBigEndianPlatform() ? i : (3 - i)];
Expand Down Expand Up @@ -289,7 +289,7 @@ namespace Exiv2
std::string id;
// Check that the string has a '\0' terminator.
const char* str = (const char*)data.pData_ + skip;
const size_t maxlen = static_cast<size_t>(data.size_ - skip);
const auto maxlen = static_cast<size_t>(data.size_ - skip);
enforce(strnlen(str, maxlen) < maxlen, Exiv2::kerCorruptedMetadata);
std::string name(str);
if ( !name.find("Exif") ) { // "Exif" or "ExifExif"
Expand Down
2 changes: 1 addition & 1 deletion src/canonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3212,7 +3212,7 @@ namespace Exiv2 {
val = -val;
}
// remove fraction
float frac = static_cast<float>(val & 0x1f);
auto frac = static_cast<float>(val & 0x1f);
val -= long(frac);
// convert 1/3 (0x0c) and 2/3 (0x14) codes
if (frac == 0x0c) {
Expand Down
4 changes: 2 additions & 2 deletions src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ namespace Exiv2 {
auto pos = exifData_->findKey(ExifKey(from));
if (pos == exifData_->end()) return;
if (!prepareXmpTarget(to)) return;
const CommentValue* cv = dynamic_cast<const CommentValue*>(&pos->value());
const auto cv = dynamic_cast<const CommentValue*>(&pos->value());
if (cv == 0) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
Expand Down Expand Up @@ -1530,7 +1530,7 @@ namespace {
return false;
}
std::string outstr;
EXV_ICONV_CONST char* inptr = const_cast<char*>(str.c_str());
auto inptr = const_cast<char*>(str.c_str());
size_t inbytesleft = str.length();
while (inbytesleft) {
char outbuf[256];
Expand Down
2 changes: 1 addition & 1 deletion src/crwimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ namespace Exiv2 {
CiffComponent* cc = pHead->findComponent(pCrwMapping->crwTagId_,
pCrwMapping->crwDir_);
if (!comment.empty()) {
uint32_t size = static_cast<uint32_t>(comment.size());
auto size = static_cast<uint32_t>(comment.size());
if (cc && cc->size() > size) size = cc->size();
DataBuf buf(size);
std::memset(buf.pData_, 0x0, buf.size_);
Expand Down
6 changes: 3 additions & 3 deletions src/easyaccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace {
int count)
{
for (int i = 0; i < count; ++i) {
ExifData::const_iterator pos = ed.findKey(ExifKey(keys[i]));
auto pos = ed.findKey(ExifKey(keys[i]));
if (pos != ed.end()) return pos;
}
return ed.end();
Expand Down Expand Up @@ -127,7 +127,7 @@ namespace Exiv2 {

// Find the first ISO value which is not "0"
const int cnt = EXV_COUNTOF(keys);
ExifData::const_iterator md = ed.end();
auto md = ed.end();
long iso_val = -1;
for (int idx = 0; idx < cnt; ) {
md = findMetadatum(ed, keys + idx, cnt - idx);
Expand All @@ -146,7 +146,7 @@ namespace Exiv2 {
// ISO value (see EXIF 2.3 Annex G)
long iso_tmp_val = -1;
while (iso_tmp_val == -1 && (iso_val == 65535 || md == ed.end())) {
ExifData::const_iterator md_st = findMetadatum(ed, sensitivityType, 1);
auto md_st = findMetadatum(ed, sensitivityType, 1);
// no SensitivityType? exit with existing data
if (md_st == ed.end())
break;
Expand Down
2 changes: 1 addition & 1 deletion src/exif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ namespace Exiv2 {
Exifdatum& ExifData::operator[](const std::string& key)
{
ExifKey exifKey(key);
iterator pos = findKey(exifKey);
auto pos = findKey(exifKey);
if (pos == end()) {
add(Exifdatum(exifKey));
pos = findKey(exifKey);
Expand Down
8 changes: 4 additions & 4 deletions src/exiv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ int Params::evalGrep( const std::string& optArg)
// there was an error compiling the regexp
if( errcode ) {
size_t length = regerror (errcode, pRegex, NULL, 0);
char *buffer = new char[ length];
auto buffer = new char[length];
regerror (errcode, pRegex, buffer, length);
std::cerr << progname()
<< ": " << _("Option") << " -g: "
Expand Down Expand Up @@ -958,7 +958,7 @@ int Params::nonoption(const std::string& argv)
static int readFileToBuf(FILE* f,Exiv2::DataBuf& buf)
{
const int buff_size = 4*1028;
Exiv2::byte* bytes = (Exiv2::byte*)::malloc(buff_size);
auto bytes = (Exiv2::byte*)::malloc(buff_size);
int nBytes = 0 ;
bool more = bytes != NULL;
while ( more ) {
Expand Down Expand Up @@ -1039,7 +1039,7 @@ using long_t = std::map<std::string, std::string>;

int Params::getopt(int argc, char* const Argv[])
{
char** argv = new char* [argc+1];
auto argv = new char*[argc + 1];
argv[argc] = NULL;
long_t longs;

Expand Down Expand Up @@ -1167,7 +1167,7 @@ namespace {
bool parseTime(const std::string& ts, long& time)
{
std::string hstr, mstr, sstr;
char *cts = new char[ts.length() + 1];
auto cts = new char[ts.length() + 1];
strcpy(cts, ts.c_str());
char *tmp = ::strtok(cts, ":");
if (tmp) hstr = tmp;
Expand Down
12 changes: 6 additions & 6 deletions src/futils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace Exiv2 {
const char* pstr = str;
// \todo try to use std::string for buf and avoid the creation of another string for just
// returning the final value
char* buf = new char[strlen(str) * 3 + 1];
auto buf = new char[strlen(str) * 3 + 1];
char* pbuf = buf;
while (*pstr) {
if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~')
Expand All @@ -114,7 +114,7 @@ namespace Exiv2 {

char* urldecode(const char* str) {
const char* pstr = str;
char* buf = new char [(strlen(str) + 1)];
auto buf = new char[(strlen(str) + 1)];
char* pbuf = buf;
while (*pstr) {
if (*pstr == '%') {
Expand Down Expand Up @@ -150,13 +150,13 @@ namespace Exiv2 {
'4', '5', '6', '7', '8', '9', '+', '/'};

int base64encode(const void* data_buf, size_t dataLength, char* result, size_t resultSize) {
char* encoding_table = (char*)base64_encode;
auto encoding_table = (char*)base64_encode;
size_t mod_table[] = {0, 2, 1};

size_t output_length = 4 * ((dataLength + 2) / 3);
int rc = result && data_buf && output_length < resultSize ? 1 : 0;
if ( rc ) {
const unsigned char* data = (const unsigned char*) data_buf ;
const auto data = (const unsigned char*)data_buf;
for (size_t i = 0, j = 0 ; i < dataLength;) {

uint32_t octet_a = i < dataLength ? data[i++] : 0 ;
Expand All @@ -183,13 +183,13 @@ namespace Exiv2 {
size_t input_length = in ? ::strlen(in) : 0;
if (!in || input_length % 4 != 0) return result;

unsigned char* encoding_table = (unsigned char*)base64_encode;
auto encoding_table = (unsigned char*)base64_encode;
unsigned char decoding_table[256];
for (unsigned char i = 0; i < 64; i++)
decoding_table[encoding_table[i]] = i;

size_t output_length = input_length / 4 * 3;
const unsigned char* buff = (const unsigned char*) in;
const auto buff = (const unsigned char*)in;

if (buff[input_length - 1] == '=') (output_length)--;
if (buff[input_length - 2] == '=') (output_length)--;
Expand Down
Loading

0 comments on commit b871218

Please sign in to comment.