Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy: use nullptr #1678

Merged
merged 1 commit into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
345 changes: 159 additions & 186 deletions samples/Jzon.cpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion samples/addmoddel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ try {
v = pos->getValue();
// Downcast the Value pointer to its actual type
auto prv = dynamic_cast<Exiv2::URationalValue*>(v.release());
if (prv == 0) throw Exiv2::Error(Exiv2::kerErrorMessage, "Downcast failed");
if (prv == nullptr)
throw Exiv2::Error(Exiv2::kerErrorMessage, "Downcast failed");
rv = Exiv2::URationalValue::UniquePtr(prv);
// Modify the value directly through the interface of URationalValue
rv->value_[2] = std::make_pair(88,77);
Expand Down
5 changes: 3 additions & 2 deletions samples/exiv2json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct Token {
using Tokens = std::vector<Token>;

// "XMP.xmp.MP.RegionInfo/MPRI:Regions[1]/MPReg:Rectangle"
bool getToken(std::string& in,Token& token, std::set<std::string>* pNS=NULL)
bool getToken(std::string& in, Token& token, std::set<std::string>* pNS = nullptr)
{
bool result = false;
bool ns = false;
Expand Down Expand Up @@ -119,7 +119,8 @@ Jzon::Node& recursivelyBuildTree(Jzon::Node& root,Tokens& tokens,size_t k)
}

// build the json tree for this key. return location and discover the name
Jzon::Node& objectForKey(const std::string& Key,Jzon::Object& root,std::string& name,std::set<std::string>* pNS=NULL)
Jzon::Node& objectForKey(const std::string& Key, Jzon::Object& root, std::string& name,
std::set<std::string>* pNS = nullptr)
{
// Parse the key
Tokens tokens ;
Expand Down
30 changes: 12 additions & 18 deletions samples/geotag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Position;
using TimeDict_t = std::map<time_t, Position>;
using TimeDict_i = std::map<time_t, Position>::iterator;
using strings_t = std::vector<std::string>;
const char* gDeg = NULL ; // string "°" or "deg"
const char* gDeg = nullptr; // string "°" or "deg"
TimeDict_t gTimeDict ;
strings_t gFiles;

Expand Down Expand Up @@ -439,7 +439,7 @@ time_t parseTime(const char* arg,bool bAdjust)
// West of GMT is negative (PDT = Pacific Daylight = -07:00 == -25200 seconds
int timeZoneAdjust()
{
time_t now = time(NULL);
time_t now = time(nullptr);
int offset;

#if defined(_MSC_VER) || defined(__MINGW__)
Expand Down Expand Up @@ -531,14 +531,12 @@ bool readDir(const char* path,Options& options)
}
#else
DIR* dir = opendir (path);
if (dir != NULL)
{
if (dir != nullptr) {
bResult = true;
struct dirent* ent;

// print all the files and directories within directory
while ((ent = readdir (dir)) != NULL)
{
while ((ent = readdir(dir)) != nullptr) {
std::string pathName = makePath(path,ent->d_name);
struct stat buf ;
lstat(path, &buf );
Expand Down Expand Up @@ -566,7 +564,7 @@ inline size_t sip(FILE* f,char* buffer,size_t max_len,size_t len)
bool readXML(const char* path,Options& options)
{
FILE* f = fopen(path,"r");
XML_Parser parser = XML_ParserCreate(NULL);
XML_Parser parser = XML_ParserCreate(nullptr);
bool bResult = f && parser ;
if ( bResult ) {
char buffer[8*1024];
Expand Down Expand Up @@ -617,18 +615,14 @@ bool readImage(const char* path,Options& /* options */)
return bResult ;
}

time_t readImageTime(const std::string& path,std::string* pS=NULL)
time_t readImageTime(const std::string& path, std::string* pS = nullptr)
{
using namespace Exiv2;

time_t result = 0 ;

const char* dateStrings[] =
{ "Exif.Photo.DateTimeOriginal"
, "Exif.Photo.DateTimeDigitized"
, "Exif.Image.DateTime"
, NULL
};
const char* dateStrings[] = {"Exif.Photo.DateTimeOriginal", "Exif.Photo.DateTimeDigitized", "Exif.Image.DateTime",
nullptr};
const char* dateString = dateStrings[0] ;

do {
Expand Down Expand Up @@ -668,8 +662,8 @@ int readFile(const char* path, const Options& /* options */)
if ( f ) {
const char* ext = strstr(path,".");
if ( ext ) {
const char* docs[] = { ".doc",".txt", NULL };
const char* code[] = { ".cpp",".h" ,".pl" ,".py" ,".pyc", NULL };
const char* docs[] = {".doc", ".txt", nullptr};
const char* code[] = {".cpp", ".h", ".pl", ".py", ".pyc", nullptr};
if ( sina(ext,docs) )
nResult = typeDoc;
if ( sina(ext,code) )
Expand All @@ -683,7 +677,7 @@ int readFile(const char* path, const Options& /* options */)

Position* searchTimeDict(TimeDict_t& td, const time_t& time,long long delta)
{
Position* result = NULL;
Position* result = nullptr;
for ( int t = 0 ; !result && t < delta ; t++ ) {
for ( int x = 0 ; !result && x < 2 ; x++ ) {
int T = t * ((x==0)?-1:1);
Expand Down Expand Up @@ -857,7 +851,7 @@ int main(int argc,const char* argv[])
#ifdef __APPLE__
char buffer[1024];
#else
char* buffer = NULL;
char* buffer = nullptr;
#endif
char* path = realpath(arg,buffer);
if ( t && path ) {
Expand Down
2 changes: 1 addition & 1 deletion samples/iotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int main(int argc, char* const argv[])
int blocksize = argc==6 ? atoi(ba) : 10000;
// ensure blocksize is sane
if (blocksize>1024*1024) blocksize=10000;
Exiv2::byte* bytes = blocksize>0 ? new Exiv2::byte[blocksize]: NULL;
Exiv2::byte* bytes = blocksize > 0 ? new Exiv2::byte[blocksize] : nullptr;

// copy fileIn from a remote location.
BasicIo::UniquePtr io = Exiv2::ImageFactory::createIo(fr);
Expand Down
2 changes: 1 addition & 1 deletion samples/largeiptc-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int main(int argc, char* const argv[])
std::cout << "IPTC fields: " << iptcData.size() << "\n";

// Set IRB, compare with IPTC raw data
Exiv2::DataBuf irb = Exiv2::Photoshop::setIptcIrb(0, 0, iptcData);
Exiv2::DataBuf irb = Exiv2::Photoshop::setIptcIrb(nullptr, 0, iptcData);
std::cout << "IRB buffer : " << irb.size_ << "\n";
const Exiv2::byte* record;
uint32_t sizeHdr;
Expand Down
4 changes: 2 additions & 2 deletions samples/tiff-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void mini1(const char* path)
WriteMethod wm;

// Write nothing to a new structure, without a previous binary image
wm = ExifParser::encode(blob, 0, 0, bigEndian, exifData);
wm = ExifParser::encode(blob, nullptr, 0, bigEndian, exifData);
enforce(wm == wmIntrusive, Exiv2::kerErrorMessage, "encode returned an unexpected value");
assert(blob.empty());
std::cout << "Test 1: Writing empty Exif data without original binary data: ok.\n";
Expand All @@ -80,7 +80,7 @@ void mini1(const char* path)

// Write something to a new structure, without a previous binary image
exifData["Exif.Photo.DateTimeOriginal"] = "Yesterday at noon";
wm = ExifParser::encode(blob, 0, 0, bigEndian, exifData);
wm = ExifParser::encode(blob, nullptr, 0, bigEndian, exifData);
enforce(wm == wmIntrusive, Exiv2::kerErrorMessage, "encode returned an unexpected value");
std::cout << "Test 3: Wrote non-empty Exif data without original binary data:\n";
exifData.clear();
Expand Down
28 changes: 13 additions & 15 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,24 @@ namespace Action {
return UniquePtr(clone_());
}

TaskFactory* TaskFactory::instance_ = 0;
TaskFactory* TaskFactory::instance_ = nullptr;

TaskFactory& TaskFactory::instance()
{
if (0 == instance_) {
if (nullptr == instance_) {
instance_ = new TaskFactory;
}
return *instance_;
} // TaskFactory::instance

void TaskFactory::cleanup()
{
if (instance_ != 0) {
if (instance_ != nullptr) {
for (auto&& i : registry_) {
delete i.second;
}
delete instance_;
instance_ = 0;
instance_ = nullptr;
}
} //TaskFactory::cleanup

Expand Down Expand Up @@ -409,9 +409,7 @@ namespace Action {
if (md != exifData.end()) {
md->write(std::cout, &exifData);
rc = 1;
}
else if (NULL != easyAccessFctFallback)
{
} else if (nullptr != easyAccessFctFallback) {
md = easyAccessFctFallback(exifData);
if (md != exifData.end()) {
md->write(std::cout, &exifData);
Expand Down Expand Up @@ -493,7 +491,7 @@ namespace Action {
if (result)
break;
#if defined(EXV_HAVE_REGEX_H)
result = regexec(&g, key.c_str(), 0, NULL, 0) == 0;
result = regexec(&g, key.c_str(), 0, nullptr, 0) == 0;
#else
std::string Pattern(g.pattern_);
std::string Key(key);
Expand Down Expand Up @@ -1387,7 +1385,7 @@ namespace Action {
Exiv2::ExifData& exifData = pImage->exifData();
Exiv2::IptcData& iptcData = pImage->iptcData();
Exiv2::XmpData& xmpData = pImage->xmpData();
Exiv2::Metadatum* metadatum = 0;
Exiv2::Metadatum* metadatum = nullptr;
if (modifyCmd.metadataId_ == exif) {
auto pos = exifData.findKey(Exiv2::ExifKey(modifyCmd.key_));
if (pos != exifData.end()) {
Expand All @@ -1413,9 +1411,7 @@ namespace Action {
if (metadatum) {
value = metadatum->getValue();
}
if ( value.get() == 0
|| ( modifyCmd.explicitType_
&& modifyCmd.typeId_ != value->typeId())) {
if (value.get() == nullptr || (modifyCmd.explicitType_ && modifyCmd.typeId_ != value->typeId())) {
value = Exiv2::Value::create(modifyCmd.typeId_);
}
int rc = value->read(modifyCmd.value_);
Expand Down Expand Up @@ -1809,7 +1805,8 @@ namespace {
if (timeStr.length() < 19) return 2;
if ( (timeStr[4] != ':' && timeStr[4] != '-') || (timeStr[7] != ':' && timeStr[7] != '-') || timeStr[10] != ' '
|| timeStr[13] != ':' || timeStr[16] != ':') return 3;
if (0 == tm) return 4;
if (nullptr == tm)
return 4;
std::memset(tm, 0x0, sizeof(struct tm));
tm->tm_isdst = -1;

Expand Down Expand Up @@ -1842,7 +1839,8 @@ namespace {

std::string tm2Str(const struct tm* tm)
{
if (0 == tm) return "";
if (nullptr == tm)
return "";

std::ostringstream os;
os << std::setfill('0')
Expand Down Expand Up @@ -2181,7 +2179,7 @@ namespace {
{
const std::string& str( strAndWidth.first);
size_t minChCount( strAndWidth.second);
size_t count = mbstowcs( NULL, str.c_str(), 0); // returns 0xFFFFFFFF on error
size_t count = mbstowcs(nullptr, str.c_str(), 0); // returns 0xFFFFFFFF on error
if( count < minChCount)
{
minChCount += str.size() - count;
Expand Down
Loading