Skip to content

Commit

Permalink
TS-4977: Prefer nullptr to NULL.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeach committed Oct 28, 2016
1 parent a5c11a8 commit ced4da1
Show file tree
Hide file tree
Showing 543 changed files with 7,533 additions and 7,349 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
@@ -1 +1 @@
Checks: -*,readability-braces-around-statements
Checks: -*,readability-braces-around-statements,modernize-use-nullptr
72 changes: 36 additions & 36 deletions cmd/traffic_cop/traffic_cop.cc
Expand Up @@ -339,7 +339,7 @@ set_alarm_death()

cop_log_trace("Entering set_alarm_death()\n");
#if defined(solaris)
action.sa_handler = NULL;
action.sa_handler = nullptr;
action.sa_sigaction = sig_fatal;
sigemptyset(&action.sa_mask);
action.sa_flags = SA_SIGINFO;
Expand All @@ -349,7 +349,7 @@ set_alarm_death()
action.sa_flags = 0;
#endif

sigaction(SIGALRM, &action, NULL);
sigaction(SIGALRM, &action, nullptr);
cop_log_trace("Leaving set_alarm_death()\n");
}

Expand All @@ -360,7 +360,7 @@ set_alarm_warn()

cop_log_trace("Entering set_alarm_warn()\n");
#if defined(solaris)
action.sa_handler = NULL;
action.sa_handler = nullptr;
action.sa_sigaction = sig_alarm_warn;
sigemptyset(&action.sa_mask);
action.sa_flags = SA_SIGINFO;
Expand All @@ -370,7 +370,7 @@ set_alarm_warn()
action.sa_flags = 0;
#endif

sigaction(SIGALRM, &action, NULL);
sigaction(SIGALRM, &action, nullptr);
cop_log_trace("Leaving set_alarm_warn()\n");
}

Expand Down Expand Up @@ -441,7 +441,7 @@ millisleep(int ms)
cop_log_trace("Entering millisleep(%d)\n", ms);
ts.tv_sec = ms / 1000;
ts.tv_nsec = (ms - ts.tv_sec * 1000) * 1000 * 1000;
nanosleep(&ts, NULL);
nanosleep(&ts, nullptr);
cop_log_trace("Leaving millisleep(%d)\n", ms);
}

Expand Down Expand Up @@ -489,7 +489,7 @@ static void
config_register_default(const RecordElement *record, void *)
{
if (record->type == RECT_CONFIG || record->type == RECT_LOCAL) {
const char *value = record->value ? record->value : ""; // splooch NULL values so std::string can swallow them
const char *value = record->value ? record->value : ""; // splooch nullptr values so std::string can swallow them
configTable[std::string(record->name)] = ConfigValue(record->type, record->value_type, value);
}
}
Expand Down Expand Up @@ -628,7 +628,7 @@ config_reload_records()
}

configTable.clear();
RecordsConfigIterate(config_register_default, NULL);
RecordsConfigIterate(config_register_default, nullptr);

if (RecConfigFileParse(config_file, config_register_variable, false) != REC_ERR_OKAY) {
cop_log(COP_FATAL, "could not parse \"%s\"\n", config_file);
Expand Down Expand Up @@ -702,7 +702,7 @@ config_reload_records()
static void
get_admin_user()
{
struct passwd *pwd = NULL;
struct passwd *pwd = nullptr;

if (!admin_user) {
admin_user = (char *)ats_malloc(MAX_LOGIN);
Expand Down Expand Up @@ -775,8 +775,8 @@ spawn_manager()
EnableDeathSignal(SIGTERM);

// Bind stdout and stderr of traffic_manager to traffic.out
execl(prog, prog, "--" TM_OPT_BIND_STDOUT, log_file, "--" TM_OPT_BIND_STDERR, log_file, NULL);
cop_log_trace("Somehow execv(%s, options, NULL) failed: %s (%d)!\n", prog, strerror(errno), errno);
execl(prog, prog, "--" TM_OPT_BIND_STDOUT, log_file, "--" TM_OPT_BIND_STDERR, log_file, nullptr);
cop_log_trace("Somehow execv(%s, options, nullptr) failed: %s (%d)!\n", prog, strerror(errno), errno);
exit(1);
} else if (child == -1) {
cop_log(COP_FATAL, "unable to fork [%d '%s']\n", errno, strerror(errno));
Expand Down Expand Up @@ -821,12 +821,12 @@ poll_write(int fd, int timeout)
}

static int
open_socket(int port, const char *ip = NULL, const char *ip_to_bind = NULL)
open_socket(int port, const char *ip = nullptr, const char *ip_to_bind = nullptr)
{
int sock = 0;
struct addrinfo hints;
struct addrinfo *result = NULL;
struct addrinfo *result_to_bind = NULL;
struct addrinfo *result = nullptr;
struct addrinfo *result_to_bind = nullptr;
char port_str[8] = {'\0'};
int err = 0;

Expand Down Expand Up @@ -869,7 +869,7 @@ open_socket(int port, const char *ip = NULL, const char *ip_to_bind = NULL)
hints.ai_family = result->ai_family;
hints.ai_socktype = result->ai_socktype;

err = getaddrinfo(ip_to_bind, NULL, &hints, &result_to_bind);
err = getaddrinfo(ip_to_bind, nullptr, &hints, &result_to_bind);
if (err != 0) {
cop_log(COP_WARNING, "(test) unable to get address info [%d %s] at ip %s\n", err, gai_strerror(err), ip_to_bind);
freeaddrinfo(result_to_bind);
Expand Down Expand Up @@ -936,7 +936,7 @@ open_socket(int port, const char *ip = NULL, const char *ip_to_bind = NULL)

static int
test_port(int port, const char *request, char *buffer, int bufsize, int64_t test_timeout, const char *ip = NULL,
const char *ip_to_bind = NULL)
const char *ip_to_bind = nullptr)
{
int64_t start_time, timeout;
int sock;
Expand Down Expand Up @@ -1167,7 +1167,7 @@ test_rs_port()
static int
test_mgmt_cli_port()
{
TSString val = NULL;
TSString val = nullptr;
int ret = 0;

if (TSRecordGetString("proxy.config.manager_binary", &val) != TS_ERR_OKAY) {
Expand All @@ -1187,7 +1187,7 @@ test_mgmt_cli_port()
}

static int
test_http_port(int port, char *request, int timeout, const char *ip = NULL, char const *ip_to_bind = NULL)
test_http_port(int port, char *request, int timeout, const char *ip = nullptr, char const *ip_to_bind = nullptr)
{
char buffer[4096];
char *p;
Expand Down Expand Up @@ -1689,23 +1689,23 @@ init_signals()
sigemptyset(&action.sa_mask);
action.sa_flags = 0;

sigaction(SIGTERM, &action, NULL);
sigaction(SIGINT, &action, NULL);
sigaction(SIGTERM, &action, nullptr);
sigaction(SIGINT, &action, nullptr);

// Handle the SIGCHLD signal. We simply reap all children that
// die (which should only be spawned traffic_manager's).
action.sa_handler = sig_child;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;

sigaction(SIGCHLD, &action, NULL);
sigaction(SIGCHLD, &action, nullptr);

// Handle a bunch of fatal signals. We simply call abort() when
// these signals arrive in order to generate a core. There is some
// difficulty with generating core files when linking with libthread
// under solaris.
#if defined(solaris)
action.sa_handler = NULL;
action.sa_handler = nullptr;
action.sa_sigaction = sig_fatal;
#else
action.sa_handler = sig_fatal;
Expand All @@ -1717,14 +1717,14 @@ init_signals()
action.sa_flags = 0;
#endif

sigaction(SIGQUIT, &action, NULL);
sigaction(SIGILL, &action, NULL);
sigaction(SIGFPE, &action, NULL);
sigaction(SIGBUS, &action, NULL);
sigaction(SIGSEGV, &action, NULL);
sigaction(SIGQUIT, &action, nullptr);
sigaction(SIGILL, &action, nullptr);
sigaction(SIGFPE, &action, nullptr);
sigaction(SIGBUS, &action, nullptr);
sigaction(SIGSEGV, &action, nullptr);
#if !defined(linux)
sigaction(SIGEMT, &action, NULL);
sigaction(SIGSYS, &action, NULL);
sigaction(SIGEMT, &action, nullptr);
sigaction(SIGSYS, &action, nullptr);
#endif

// Handle the SIGALRM signal. We use this signal to make sure the
Expand All @@ -1737,7 +1737,7 @@ init_signals()
sigemptyset(&action.sa_mask);
action.sa_flags = 0;

sigaction(SIGPIPE, &action, NULL);
sigaction(SIGPIPE, &action, nullptr);
cop_log_trace("Leaving init_signals()\n");
}

Expand Down Expand Up @@ -1794,7 +1794,7 @@ init()

// Start up the records store and load the defaults so that we can locate our configuration.
RecConfigFileInit();
RecordsConfigIterate(config_register_default, NULL);
RecordsConfigIterate(config_register_default, nullptr);

init_signals();
init_syslog();
Expand All @@ -1816,9 +1816,9 @@ init()
}

static const ArgumentDescription argument_descriptions[] = {
{"debug", 'd', "Enable debug logging", "F", &debug_flag, NULL, NULL},
{"stdout", 'o', "Print log messages to standard output", "F", &stdout_flag, NULL, NULL},
{"stop", 's', "Send child processes SIGSTOP instead of SIGKILL", "F", &stop_flag, NULL, NULL},
{"debug", 'd', "Enable debug logging", "F", &debug_flag, nullptr, nullptr},
{"stdout", 'o', "Print log messages to standard output", "F", &stdout_flag, nullptr, nullptr},
{"stop", 's', "Send child processes SIGSTOP instead of SIGKILL", "F", &stop_flag, nullptr, nullptr},
HELP_ARGUMENT_DESCRIPTION(),
VERSION_ARGUMENT_DESCRIPTION()};

Expand All @@ -1844,15 +1844,15 @@ main(int /* argc */, const char *argv[])
signal(SIGTTIN, SIG_IGN);

// setup supplementary groups if it is not set. any way, worth a try.
if (0 == getgroups(0, NULL)) {
if (0 == getgroups(0, nullptr)) {
uid_t uid = getuid();
gid_t gid = getgid();

const int bufSize = 1024;
char buf[bufSize];

struct passwd passwdInfo;
struct passwd *ppasswd = NULL;
struct passwd *ppasswd = nullptr;
int res;
res = getpwuid_r(uid, &passwdInfo, buf, bufSize, &ppasswd);
if (!res && ppasswd) {
Expand Down Expand Up @@ -1891,7 +1891,7 @@ main(int /* argc */, const char *argv[])

// Initialize and start it up.
init();
check(NULL);
check(nullptr);

return 0;
}
4 changes: 2 additions & 2 deletions cmd/traffic_crashlog/procinfo.cc
Expand Up @@ -43,7 +43,7 @@ procfd_readlink(pid_t pid, const char *fname)
nbytes = readlink(path, resolved, MAXPATHLEN);
if (nbytes == -1) {
Note("readlink failed with %s", strerror(errno));
return NULL;
return nullptr;
}

resolved[nbytes] = '\0';
Expand Down Expand Up @@ -144,7 +144,7 @@ crashlog_write_datime(FILE *fp, const crashlog_target &target)
bool
crashlog_write_backtrace(FILE *fp, const crashlog_target &)
{
TSString trace = NULL;
TSString trace = nullptr;
TSMgmtError mgmterr;

// NOTE: sometimes we can't get a backtrace because the ptrace attach will fail with
Expand Down
22 changes: 11 additions & 11 deletions cmd/traffic_crashlog/traffic_crashlog.cc
Expand Up @@ -34,26 +34,26 @@
static int syslog_mode = false;
static int debug_mode = false;
static int wait_mode = false;
static char *host_triplet = NULL;
static char *host_triplet = nullptr;
static int target_pid = getppid();

// If pid_t is not sizeof(int), we will have to jiggle argument parsing.
extern char __pid_size_static_assert[sizeof(pid_t) == sizeof(int) ? 0 : -1];

static AppVersionInfo appVersionInfo;
static const ArgumentDescription argument_descriptions[] = {
{"target", '-', "Target process ID", "I", &target_pid, NULL, NULL},
{"host", '-', "Host triplet for the process being logged", "S*", &host_triplet, NULL, NULL},
{"wait", '-', "Stop until signalled at startup", "F", &wait_mode, NULL, NULL},
{"syslog", '-', "Syslog after writing a crash log", "F", &syslog_mode, NULL, NULL},
{"debug", '-', "Enable debugging mode", "F", &debug_mode, NULL, NULL},
{"target", '-', "Target process ID", "I", &target_pid, nullptr, nullptr},
{"host", '-', "Host triplet for the process being logged", "S*", &host_triplet, nullptr, nullptr},
{"wait", '-', "Stop until signalled at startup", "F", &wait_mode, nullptr, nullptr},
{"syslog", '-', "Syslog after writing a crash log", "F", &syslog_mode, nullptr, nullptr},
{"debug", '-', "Enable debugging mode", "F", &debug_mode, nullptr, nullptr},
HELP_ARGUMENT_DESCRIPTION(),
VERSION_ARGUMENT_DESCRIPTION()};

static struct tm
timestamp()
{
time_t now = time(NULL);
time_t now = time(nullptr);
struct tm tm;

localtime_r(&now, &tm);
Expand All @@ -80,7 +80,7 @@ crashlog_open(const char *path)
int fd;

fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0400);
return (fd == -1) ? NULL : fdopen(fd, "w");
return (fd == -1) ? nullptr : fdopen(fd, "w");
}

int
Expand Down Expand Up @@ -118,7 +118,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
}

Layout::create();
RecProcessInit(RECM_STAND_ALONE, NULL /* diags */);
RecProcessInit(RECM_STAND_ALONE, nullptr /* diags */);
LibRecordsConfigInit();

if (syslog_mode) {
Expand Down Expand Up @@ -148,7 +148,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
Note("crashlog started, target=%ld, debug=%s syslog=%s, uid=%ld euid=%ld", (long)target_pid, debug_mode ? "true" : "false",
syslog_mode ? "true" : "false", (long)getuid(), (long)geteuid());

mgmterr = TSInit(NULL, (TSInitOptionT)(TS_MGMT_OPT_NO_EVENTS | TS_MGMT_OPT_NO_SOCK_TESTS));
mgmterr = TSInit(nullptr, (TSInitOptionT)(TS_MGMT_OPT_NO_EVENTS | TS_MGMT_OPT_NO_SOCK_TESTS));
if (mgmterr != TS_ERR_OKAY) {
char *msg = TSGetErrorMessage(mgmterr);
Warning("failed to intialize management API: %s", msg);
Expand Down Expand Up @@ -179,7 +179,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
logname = crashlog_name();

fp = debug_mode ? stdout : crashlog_open(logname);
if (fp == NULL) {
if (fp == nullptr) {
Error("failed to create '%s': %s", logname, strerror(errno));
return 1;
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/traffic_ctl/alarm.cc
Expand Up @@ -47,8 +47,8 @@ alarm_list(unsigned argc, const char **argv)
TSMgmtError error;
CtrlAlarmList alarms;

if (!CtrlProcessArguments(argc, argv, NULL, 0) || n_file_arguments != 0) {
return CtrlCommandUsage("alarm list", NULL, 0);
if (!CtrlProcessArguments(argc, argv, nullptr, 0) || n_file_arguments != 0) {
return CtrlCommandUsage("alarm list", nullptr, 0);
}

error = TSActiveEventGetMlt(alarms.list);
Expand All @@ -72,8 +72,8 @@ alarm_clear(unsigned argc, const char **argv)
TSMgmtError error;
CtrlAlarmList alarms;

if (!CtrlProcessArguments(argc, argv, NULL, 0) || n_file_arguments != 0) {
return CtrlCommandUsage("alarm clear", NULL, 0);
if (!CtrlProcessArguments(argc, argv, nullptr, 0) || n_file_arguments != 0) {
return CtrlCommandUsage("alarm clear", nullptr, 0);
}

// First get the active alarms ...
Expand Down Expand Up @@ -106,8 +106,8 @@ alarm_resolve(unsigned argc, const char **argv)
TSMgmtError error;
CtrlAlarmList alarms;

if (!CtrlProcessArguments(argc, argv, NULL, 0) || n_file_arguments == 0) {
return CtrlCommandUsage("alarm resolve ALARM [ALARM ...]", NULL, 0);
if (!CtrlProcessArguments(argc, argv, nullptr, 0) || n_file_arguments == 0) {
return CtrlCommandUsage("alarm resolve ALARM [ALARM ...]", nullptr, 0);
}

for (unsigned i = 0; i < n_file_arguments; ++i) {
Expand Down

0 comments on commit ced4da1

Please sign in to comment.