Skip to content

Commit

Permalink
Use nullptr instead lf C-styled NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillbobyrev authored and pbeckingham committed May 14, 2018
1 parent 6f19a3f commit 511a235
Show file tree
Hide file tree
Showing 22 changed files with 56 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/CLI2.cpp
Expand Up @@ -1734,8 +1734,8 @@ void CLI2::insertIDExpr ()
else else
{ {
bool ascending = true; bool ascending = true;
int low = strtol (r->first.c_str (), NULL, 10); int low = strtol (r->first.c_str (), nullptr, 10);
int high = strtol (r->second.c_str (), NULL, 10); int high = strtol (r->second.c_str (), nullptr, 10);
if (low <= high) if (low <= high)
ascending = true; ascending = true;
else else
Expand Down
2 changes: 1 addition & 1 deletion src/Context.cpp
Expand Up @@ -1027,7 +1027,7 @@ void Context::getLimits (int& rows, int& lines)
} }
else else
{ {
rows = (int) strtol (limit.c_str (), NULL, 10); rows = (int) strtol (limit.c_str (), nullptr, 10);
lines = 0; lines = 0;
} }
} }
Expand Down
6 changes: 3 additions & 3 deletions src/DOM.cpp
Expand Up @@ -279,7 +279,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
else if (type == Lexer::Type::number && else if (type == Lexer::Type::number &&
token.find ('.') == std::string::npos) token.find ('.') == std::string::npos)
{ {
auto id = strtol (token.c_str (), NULL, 10); auto id = strtol (token.c_str (), nullptr, 10);
if (id && id != ref.id) if (id && id != ref.id)
Context::getContext ().tdb2.get (id, ref); Context::getContext ().tdb2.get (id, ref);


Expand Down Expand Up @@ -375,7 +375,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
{ {
auto annos = ref.getAnnotations (); auto annos = ref.getAnnotations ();


int a = strtol (elements[1].c_str (), NULL, 10); int a = strtol (elements[1].c_str (), nullptr, 10);
int count = 0; int count = 0;


// Count off the 'a'th annotation. // Count off the 'a'th annotation.
Expand Down Expand Up @@ -403,7 +403,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
{ {
auto annos = ref.getAnnotations (); auto annos = ref.getAnnotations ();


int a = strtol (elements[1].c_str (), NULL, 10); int a = strtol (elements[1].c_str (), nullptr, 10);
int count = 0; int count = 0;


// Count off the 'a'th annotation. // Count off the 'a'th annotation.
Expand Down
2 changes: 1 addition & 1 deletion src/TDB2.cpp
Expand Up @@ -1026,7 +1026,7 @@ void TDB2::show_diff (
const std::string& prior, const std::string& prior,
const std::string& when) const std::string& when)
{ {
Datetime lastChange (strtol (when.c_str (), NULL, 10)); Datetime lastChange (strtol (when.c_str (), nullptr, 10));


// Set the colors. // Set the colors.
Color color_red (Context::getContext ().color () ? Context::getContext ().config.get ("color.undo.before") : ""); Color color_red (Context::getContext ().color () ? Context::getContext ().config.get ("color.undo.before") : "");
Expand Down
8 changes: 4 additions & 4 deletions src/TLSClient.cpp
Expand Up @@ -218,7 +218,7 @@ void TLSClient::connect (const std::string& host, const std::string& port)
#if GNUTLS_VERSION_NUMBER >= 0x030406 #if GNUTLS_VERSION_NUMBER >= 0x030406
// For _trust == TLSClient::allow_all we perform no action // For _trust == TLSClient::allow_all we perform no action
if (_trust == TLSClient::ignore_hostname) if (_trust == TLSClient::ignore_hostname)
gnutls_session_set_verify_cert (_session, NULL, 0); // 3.4.6 gnutls_session_set_verify_cert (_session, nullptr, 0); // 3.4.6
else if (_trust == TLSClient::strict) else if (_trust == TLSClient::strict)
gnutls_session_set_verify_cert (_session, _host.c_str (), 0); // 3.4.6 gnutls_session_set_verify_cert (_session, _host.c_str (), 0); // 3.4.6
#endif #endif
Expand Down Expand Up @@ -251,7 +251,7 @@ void TLSClient::connect (const std::string& host, const std::string& port)


// Try them all, stop on success. // Try them all, stop on success.
struct addrinfo* p; struct addrinfo* p;
for (p = res; p != NULL; p = p->ai_next) for (p = res; p != nullptr; p = p->ai_next)
{ {
if ((_socket = ::socket (p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) if ((_socket = ::socket (p->ai_family, p->ai_socktype, p->ai_protocol)) == -1)
continue; continue;
Expand All @@ -275,7 +275,7 @@ void TLSClient::connect (const std::string& host, const std::string& port)


free (res); free (res);


if (p == NULL) if (p == nullptr)
throw format ("Could not connect to {1} {2}", host, port); throw format ("Could not connect to {1} {2}", host, port);


#if GNUTLS_VERSION_NUMBER >= 0x030100 #if GNUTLS_VERSION_NUMBER >= 0x030100
Expand Down Expand Up @@ -362,7 +362,7 @@ int TLSClient::verify_certificate () const
const char* hostname = _host.c_str(); const char* hostname = _host.c_str();
#if GNUTLS_VERSION_NUMBER >= 0x030104 #if GNUTLS_VERSION_NUMBER >= 0x030104
if (_trust == TLSClient::ignore_hostname) if (_trust == TLSClient::ignore_hostname)
hostname = NULL; hostname = nullptr;


int ret = gnutls_certificate_verify_peers3 (_session, hostname, &status); // 3.1.4 int ret = gnutls_certificate_verify_peers3 (_session, hostname, &status); // 3.1.4
if (ret < 0) if (ret < 0)
Expand Down
2 changes: 1 addition & 1 deletion src/TLSClient.h
Expand Up @@ -58,7 +58,7 @@ class TLSClient
std::string _host {""}; std::string _host {""};
std::string _port {""}; std::string _port {""};
gnutls_certificate_credentials_t _credentials {}; gnutls_certificate_credentials_t _credentials {};
gnutls_session_t _session {0}; gnutls_session_t _session {nullptr};
int _socket {0}; int _socket {0};
int _limit {0}; int _limit {0};
bool _debug {false}; bool _debug {false};
Expand Down
14 changes: 7 additions & 7 deletions src/Task.cpp
Expand Up @@ -181,7 +181,7 @@ const std::string Task::identifier (bool shortened /* = false */) const
void Task::setAsNow (const std::string& att) void Task::setAsNow (const std::string& att)
{ {
char now[16]; char now[16];
snprintf (now, 16, "%u", (unsigned int) time (NULL)); snprintf (now, 16, "%u", (unsigned int) time (nullptr));
set (att, now); set (att, now);


recalc_urgency = true; recalc_urgency = true;
Expand Down Expand Up @@ -231,7 +231,7 @@ int Task::get_int (const std::string& name) const
{ {
auto i = data.find (name); auto i = data.find (name);
if (i != data.end ()) if (i != data.end ())
return strtol (i->second.c_str (), NULL, 10); return strtol (i->second.c_str (), nullptr, 10);


return 0; return 0;
} }
Expand All @@ -241,7 +241,7 @@ unsigned long Task::get_ulong (const std::string& name) const
{ {
auto i = data.find (name); auto i = data.find (name);
if (i != data.end ()) if (i != data.end ())
return strtoul (i->second.c_str (), NULL, 10); return strtoul (i->second.c_str (), nullptr, 10);


return 0; return 0;
} }
Expand All @@ -251,7 +251,7 @@ float Task::get_float (const std::string& name) const
{ {
auto i = data.find (name); auto i = data.find (name);
if (i != data.end ()) if (i != data.end ())
return strtof (i->second.c_str (), NULL); return strtof (i->second.c_str (), nullptr);


return 0.0; return 0.0;
} }
Expand All @@ -261,7 +261,7 @@ time_t Task::get_date (const std::string& name) const
{ {
auto i = data.find (name); auto i = data.find (name);
if (i != data.end ()) if (i != data.end ())
return (time_t) strtoul (i->second.c_str (), NULL, 10); return (time_t) strtoul (i->second.c_str (), nullptr, 10);


return 0; return 0;
} }
Expand Down Expand Up @@ -1060,7 +1060,7 @@ bool Task::hasAnnotations () const
// timestamp. // timestamp.
void Task::addAnnotation (const std::string& description) void Task::addAnnotation (const std::string& description)
{ {
time_t now = time (NULL); time_t now = time (nullptr);
std::string key; std::string key;


do do
Expand Down Expand Up @@ -1930,7 +1930,7 @@ float Task::urgency_active () const
float Task::urgency_scheduled () const float Task::urgency_scheduled () const
{ {
if (has ("scheduled") && if (has ("scheduled") &&
get_date ("scheduled") < time (NULL)) get_date ("scheduled") < time (nullptr))
return 1.0; return 1.0;


return 0.0; return 0.0;
Expand Down
4 changes: 2 additions & 2 deletions src/Variant.cpp
Expand Up @@ -1864,9 +1864,9 @@ void Variant::cast (const enum type new_type)
_string == "0.0") ? false : true; _string == "0.0") ? false : true;
break; break;
case type_integer: case type_integer:
_integer = (int) strtol (_string.c_str (), NULL, (_string.substr (0, 2) == "0x" ? 16 : 10)); _integer = (int) strtol (_string.c_str (), nullptr, (_string.substr (0, 2) == "0x" ? 16 : 10));
break; break;
case type_real: _real = strtod (_string.c_str (), NULL); break; case type_real: _real = strtod (_string.c_str (), nullptr); break;
case type_string: break; case type_string: break;
case type_date: case type_date:
{ {
Expand Down
4 changes: 2 additions & 2 deletions src/columns/ColDepends.cpp
Expand Up @@ -154,14 +154,14 @@ void ColumnDepends::modify (Task& task, const std::string& value)
if (dep.length () == 37) if (dep.length () == 37)
task.removeDependency (dep.substr (1)); task.removeDependency (dep.substr (1));
else else
task.removeDependency (strtol (dep.substr (1).c_str (), NULL, 10)); task.removeDependency (strtol (dep.substr (1).c_str (), nullptr, 10));
} }
else else
{ {
if (dep.length () == 36) if (dep.length () == 36)
task.addDependency (dep); task.addDependency (dep);
else else
task.addDependency (strtol (dep.c_str (), NULL, 10)); task.addDependency (strtol (dep.c_str (), nullptr, 10));
} }
} }
} }
Expand Down
4 changes: 2 additions & 2 deletions src/columns/ColDescription.cpp
Expand Up @@ -171,7 +171,7 @@ void ColumnDescription::render (
{ {
for (const auto& i : task.getAnnotations ()) for (const auto& i : task.getAnnotations ())
{ {
Datetime dt (strtol (i.first.substr (11).c_str (), NULL, 10)); Datetime dt (strtol (i.first.substr (11).c_str (), nullptr, 10));
description += '\n' + std::string (_indent, ' ') + dt.toString (_dateformat) + ' ' + i.second; description += '\n' + std::string (_indent, ' ') + dt.toString (_dateformat) + ' ' + i.second;
} }
} }
Expand Down Expand Up @@ -200,7 +200,7 @@ void ColumnDescription::render (
{ {
for (const auto& i : task.getAnnotations ()) for (const auto& i : task.getAnnotations ())
{ {
Datetime dt (strtol (i.first.substr (11).c_str (), NULL, 10)); Datetime dt (strtol (i.first.substr (11).c_str (), nullptr, 10));
description += ' ' + dt.toString (_dateformat) + ' ' + i.second; description += ' ' + dt.toString (_dateformat) + ' ' + i.second;
} }
} }
Expand Down
4 changes: 2 additions & 2 deletions src/columns/ColUDA.cpp
Expand Up @@ -241,7 +241,7 @@ void ColumnUDADate::measure (Task& task, unsigned int& minimum, unsigned int& ma
// rc.report.<report>.dateformat // rc.report.<report>.dateformat
// rc.dateformat.report // rc.dateformat.report
// rc.dateformat // rc.dateformat
Datetime date ((time_t) strtol (value.c_str (), NULL, 10)); Datetime date ((time_t) strtol (value.c_str (), nullptr, 10));
auto format = Context::getContext ().config.get ("report." + _report + ".dateformat"); auto format = Context::getContext ().config.get ("report." + _report + ".dateformat");
if (format == "") if (format == "")
format = Context::getContext ().config.get ("dateformat.report"); format = Context::getContext ().config.get ("dateformat.report");
Expand Down Expand Up @@ -287,7 +287,7 @@ void ColumnUDADate::render (
format = Context::getContext ().config.get ("dateformat"); format = Context::getContext ().config.get ("dateformat");
} }


renderStringLeft (lines, width, color, Datetime ((time_t) strtol (value.c_str (), NULL, 10)).toString (format)); renderStringLeft (lines, width, color, Datetime ((time_t) strtol (value.c_str (), nullptr, 10)).toString (format));
} }
else if (_style == "indicator") else if (_style == "indicator")
{ {
Expand Down
2 changes: 1 addition & 1 deletion src/columns/Column.cpp
Expand Up @@ -213,7 +213,7 @@ Column* Column::uda (const std::string& name)
else if (type != "") else if (type != "")
throw std::string ("User defined attributes may only be of type 'string', 'date', 'duration' or 'numeric'."); throw std::string ("User defined attributes may only be of type 'string', 'date', 'duration' or 'numeric'.");


return NULL; return nullptr;
} }


//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 3 additions & 3 deletions src/commands/CmdCalendar.cpp
Expand Up @@ -121,12 +121,12 @@ int CmdCalendar::execute (std::string& output)


// YYYY. // YYYY.
else if (Lexer::isAllDigits (arg) && arg.length () == 4) else if (Lexer::isAllDigits (arg) && arg.length () == 4)
argYear = strtol (arg.c_str (), NULL, 10); argYear = strtol (arg.c_str (), nullptr, 10);


// MM. // MM.
else if (Lexer::isAllDigits (arg) && arg.length () <= 2) else if (Lexer::isAllDigits (arg) && arg.length () <= 2)
{ {
argMonth = strtol (arg.c_str (), NULL, 10); argMonth = strtol (arg.c_str (), nullptr, 10);
if (argMonth < 1 || argMonth > 12) if (argMonth < 1 || argMonth > 12)
throw format ("Argument '{1}' is not a valid month.", arg); throw format ("Argument '{1}' is not a valid month.", arg);
} }
Expand Down Expand Up @@ -564,7 +564,7 @@ std::string CmdCalendar::renderMonths (
task.has ("due")) task.has ("due"))
{ {
std::string due = task.get ("due"); std::string due = task.get ("due");
Datetime duedmy (strtol (due.c_str(), NULL, 10)); Datetime duedmy (strtol (due.c_str(), nullptr, 10));


if (duedmy.day () == d && if (duedmy.day () == d &&
duedmy.month () == months[mpl] && duedmy.month () == months[mpl] &&
Expand Down
4 changes: 2 additions & 2 deletions src/commands/CmdDiagnostics.cpp
Expand Up @@ -211,9 +211,9 @@ int CmdDiagnostics::execute (std::string& output)
char* peditor; char* peditor;
if (Context::getContext ().config.get ("editor") != "") if (Context::getContext ().config.get ("editor") != "")
out << " rc.editor: " << Context::getContext ().config.get ("editor") << '\n'; out << " rc.editor: " << Context::getContext ().config.get ("editor") << '\n';
else if ((peditor = getenv ("VISUAL")) != NULL) else if ((peditor = getenv ("VISUAL")) != nullptr)
out << " $VISUAL: " << peditor << '\n'; out << " $VISUAL: " << peditor << '\n';
else if ((peditor = getenv ("EDITOR")) != NULL) else if ((peditor = getenv ("EDITOR")) != nullptr)
out << " $EDITOR: " << peditor << '\n'; out << " $EDITOR: " << peditor << '\n';


out << " Server: " out << " Server: "
Expand Down
4 changes: 2 additions & 2 deletions src/commands/CmdEdit.cpp
Expand Up @@ -249,7 +249,7 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)


for (auto& anno : task.getAnnotations ()) for (auto& anno : task.getAnnotations ())
{ {
Datetime dt (strtol (anno.first.substr (11).c_str (), NULL, 10)); Datetime dt (strtol (anno.first.substr (11).c_str (), nullptr, 10));
before << " Annotation: " << dt.toString (dateformat) before << " Annotation: " << dt.toString (dateformat)
<< " -- " << json::encode (anno.second) << '\n'; << " -- " << json::encode (anno.second) << '\n';
} }
Expand Down Expand Up @@ -652,7 +652,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (dep.length () >= 7) if (dep.length () >= 7)
task.addDependency (dep); task.addDependency (dep);
else else
task.addDependency ((int) strtol (dep.c_str (), NULL, 10)); task.addDependency ((int) strtol (dep.c_str (), nullptr, 10));
} }


// UDAs // UDAs
Expand Down
4 changes: 2 additions & 2 deletions src/commands/CmdInfo.cpp
Expand Up @@ -217,7 +217,7 @@ int CmdInfo::execute (std::string& output)
auto created = task.get ("entry"); auto created = task.get ("entry");
if (created.length ()) if (created.length ())
{ {
Datetime dt (strtol (created.c_str (), NULL, 10)); Datetime dt (strtol (created.c_str (), nullptr, 10));
age = Duration (now - dt).formatVague (); age = Duration (now - dt).formatVague ();
} }


Expand Down Expand Up @@ -531,7 +531,7 @@ int CmdInfo::execute (std::string& output)
{ {
int row = journal.addRow (); int row = journal.addRow ();


Datetime timestamp (strtol (undo[when].substr (5).c_str (), NULL, 10)); Datetime timestamp (strtol (undo[when].substr (5).c_str (), nullptr, 10));
journal.set (row, 0, timestamp.toString (dateformat)); journal.set (row, 0, timestamp.toString (dateformat));


Task before (undo[previous].substr (4)); Task before (undo[previous].substr (4));
Expand Down
6 changes: 3 additions & 3 deletions src/commands/CmdModify.h
Expand Up @@ -37,11 +37,11 @@ class CmdModify : public Command
int execute (std::string&); int execute (std::string&);
void checkConsistency (Task &before, Task &after); void checkConsistency (Task &before, Task &after);
int modifyAndUpdate (Task &before, Task &after, int modifyAndUpdate (Task &before, Task &after,
std::map <std::string, std::string> *projectChanges = NULL); std::map <std::string, std::string> *projectChanges = nullptr);
int modifyRecurrenceSiblings (Task &task, int modifyRecurrenceSiblings (Task &task,
std::map <std::string, std::string> *projectChanges = NULL); std::map <std::string, std::string> *projectChanges = nullptr);
int modifyRecurrenceParent (Task &task, int modifyRecurrenceParent (Task &task,
std::map <std::string, std::string> *projectChanges = NULL); std::map <std::string, std::string> *projectChanges = nullptr);
}; };


#endif #endif
Expand Down
6 changes: 3 additions & 3 deletions src/commands/CmdStats.cpp
Expand Up @@ -89,7 +89,7 @@ int CmdStats::execute (std::string& output)
filter.subset (all, filtered); filter.subset (all, filtered);


Datetime now; Datetime now;
time_t earliest = time (NULL); time_t earliest = time (nullptr);
time_t latest = 1; time_t latest = 1;
int totalT = 0; int totalT = 0;
int deletedT = 0; int deletedT = 0;
Expand Down Expand Up @@ -123,13 +123,13 @@ int CmdStats::execute (std::string& output)
if (task.is_blocked) ++blockedT; if (task.is_blocked) ++blockedT;
if (task.is_blocking) ++blockingT; if (task.is_blocking) ++blockingT;


time_t entry = strtol (task.get ("entry").c_str (), NULL, 10); time_t entry = strtol (task.get ("entry").c_str (), nullptr, 10);
if (entry < earliest) earliest = entry; if (entry < earliest) earliest = entry;
if (entry > latest) latest = entry; if (entry > latest) latest = entry;


if (status == Task::completed) if (status == Task::completed)
{ {
time_t end = strtol (task.get ("end").c_str (), NULL, 10); time_t end = strtol (task.get ("end").c_str (), nullptr, 10);
daysPending += (end - entry) / 86400.0; daysPending += (end - entry) / 86400.0;
} }


Expand Down
8 changes: 4 additions & 4 deletions src/commands/CmdSummary.cpp
Expand Up @@ -79,7 +79,7 @@ int CmdSummary::execute (std::string& output)
std::map <std::string, int> countCompleted; std::map <std::string, int> countCompleted;
std::map <std::string, double> sumEntry; std::map <std::string, double> sumEntry;
std::map <std::string, int> counter; std::map <std::string, int> counter;
time_t now = time (NULL); time_t now = time (nullptr);


// Initialize counters. // Initialize counters.
for (auto& project : allProjects) for (auto& project : allProjects)
Expand Down Expand Up @@ -107,7 +107,7 @@ int CmdSummary::execute (std::string& output)
{ {
++countPending[parent]; ++countPending[parent];


time_t entry = strtol (task.get ("entry").c_str (), NULL, 10); time_t entry = strtol (task.get ("entry").c_str (), nullptr, 10);
if (entry) if (entry)
sumEntry[parent] = sumEntry[parent] + (double) (now - entry); sumEntry[parent] = sumEntry[parent] + (double) (now - entry);
} }
Expand All @@ -119,8 +119,8 @@ int CmdSummary::execute (std::string& output)
{ {
++countCompleted[parent]; ++countCompleted[parent];


time_t entry = strtol (task.get ("entry").c_str (), NULL, 10); time_t entry = strtol (task.get ("entry").c_str (), nullptr, 10);
time_t end = strtol (task.get ("end").c_str (), NULL, 10); time_t end = strtol (task.get ("end").c_str (), nullptr, 10);
if (entry && end) if (entry && end)
sumEntry[parent] = sumEntry[parent] + (double) (end - entry); sumEntry[parent] = sumEntry[parent] + (double) (end - entry);
} }
Expand Down
2 changes: 1 addition & 1 deletion src/feedback.cpp
Expand Up @@ -247,7 +247,7 @@ std::string renderAttribute (const std::string& name, const std::string& value,
col->type () == "date" && col->type () == "date" &&
value != "") value != "")
{ {
Datetime d ((time_t)strtol (value.c_str (), NULL, 10)); Datetime d ((time_t)strtol (value.c_str (), nullptr, 10));
if (format == "") if (format == "")
return d.toString (Context::getContext ().config.get ("dateformat")); return d.toString (Context::getContext ().config.get ("dateformat"));


Expand Down

0 comments on commit 511a235

Please sign in to comment.