Skip to content

Commit

Permalink
Use nullptr instead of NULL.
Browse files Browse the repository at this point in the history
  • Loading branch information
rocallahan committed Oct 13, 2014
1 parent d75402e commit 1a2f524
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/AddressSpace.cc
Expand Up @@ -353,7 +353,7 @@ static void print_process_mmap_iterator(void* unused, Task* t,
* Cat the /proc/[t->tid]/maps file to stdout, line by line.
*/
static void print_process_mmap(Task* t) {
iterate_memory_map(t, print_process_mmap_iterator, NULL);
iterate_memory_map(t, print_process_mmap_iterator, nullptr);
}

AddressSpace::~AddressSpace() { session->on_destroy(this); }
Expand Down
2 changes: 1 addition & 1 deletion src/AutoRemoteSyscalls.cc
Expand Up @@ -190,7 +190,7 @@ ScopedFd AutoRemoteSyscalls::retrieve_fd(int fd) {
syscall_helper(DONT_WAIT, remote_syscall, callregs);
// Now the child is waiting for us to accept it.

int sock = accept(listen_sock, NULL, NULL);
int sock = accept(listen_sock, nullptr, nullptr);
if (sock < 0) {
FATAL() << "Failed to create parent socket";
}
Expand Down
10 changes: 5 additions & 5 deletions src/CompressedWriter.cc
Expand Up @@ -19,7 +19,7 @@ using namespace std;

void* CompressedWriter::compression_thread_callback(void* p) {
static_cast<CompressedWriter*>(p)->compression_thread();
return NULL;
return nullptr;
}

CompressedWriter::CompressedWriter(const string& filename, size_t block_size,
Expand All @@ -30,8 +30,8 @@ CompressedWriter::CompressedWriter(const string& filename, size_t block_size,
threads.resize(num_threads);
thread_pos.resize(num_threads);
buffer.resize(block_size * (num_threads + 2));
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cond, NULL);
pthread_mutex_init(&mutex, nullptr);
pthread_cond_init(&cond, nullptr);

for (uint32_t i = 0; i < num_threads; ++i) {
thread_pos[i] = UINT64_MAX;
Expand All @@ -54,7 +54,7 @@ CompressedWriter::CompressedWriter(const string& filename, size_t block_size,
// until we've finished initializing it.
pthread_mutex_lock(&mutex);
for (uint32_t i = 0; i < num_threads; ++i) {
pthread_create(&threads[i], NULL, compression_thread_callback, this);
pthread_create(&threads[i], nullptr, compression_thread_callback, this);
size_t last_slash = filename.rfind('/');
string thread_name =
string("compress ") + (last_slash == string::npos
Expand Down Expand Up @@ -211,7 +211,7 @@ void CompressedWriter::close() {
pthread_mutex_unlock(&mutex);

for (auto i = threads.begin(); i != threads.end(); ++i) {
pthread_join(*i, NULL);
pthread_join(*i, nullptr);
}

fd.close();
Expand Down
4 changes: 2 additions & 2 deletions src/Session.h
Expand Up @@ -71,10 +71,10 @@ class Session {
std::shared_ptr<TaskGroup> create_tg(Task* t);

/** Call |Task::dump(out)| for all live tasks. */
void dump_all_tasks(FILE* out = NULL);
void dump_all_tasks(FILE* out = nullptr);

/**
* Return the task created with |rec_tid|, or NULL if no such
* Return the task created with |rec_tid|, or nullptr if no such
* task exists.
*/
Task* find_task(pid_t rec_tid);
Expand Down
8 changes: 4 additions & 4 deletions src/debugger_gdb.cc
Expand Up @@ -467,7 +467,7 @@ static string decode_ascii_encoded_hex_str(const char* encoded) {
* seen, nonzero if not.
*/
static int skip_to_packet_start(struct dbg_context* dbg) {
uint8_t* p = NULL;
uint8_t* p = nullptr;
int i;

/* XXX we want memcspn() here ... */
Expand Down Expand Up @@ -573,7 +573,7 @@ static void read_binary_data(const uint8_t* payload, ssize_t data_len,
/**
* Parse and return a gdb thread-id from |str|. |endptr| points to
* the character just after the last character in the thread-id. It
* may be NULL.
* may be nullptr.
*/
static dbg_threadid_t parse_threadid(const char* str, char** endptr) {
dbg_threadid_t t;
Expand Down Expand Up @@ -933,7 +933,7 @@ static int process_vpacket(struct dbg_context* dbg, char* payload) {

static int process_packet(struct dbg_context* dbg) {
char request;
char* payload = NULL;
char* payload = nullptr;
int ret;

assert(INTERRUPT_CHAR == dbg->inbuf[0] ||
Expand Down Expand Up @@ -1569,5 +1569,5 @@ void dbg_destroy_context(struct dbg_context** dbg) {
close(d->listen_fd);
close(d->sock_fd);
free(d);
*dbg = NULL;
*dbg = nullptr;
}
2 changes: 1 addition & 1 deletion src/debugger_gdb.h
Expand Up @@ -351,7 +351,7 @@ void dbg_reply_detach(struct dbg_context* dbg);
/**
* Pass the siginfo_t and its size (as requested by the debugger) in
* |si_bytes| and |num_bytes| if successfully read. Otherwise pass
* |si_bytes = NULL|.
* |si_bytes = nullptr|.
*/
void dbg_reply_read_siginfo(struct dbg_context* dbg, const uint8_t* si_bytes,
ssize_t num_bytes);
Expand Down
67 changes: 35 additions & 32 deletions src/main.cc
Expand Up @@ -315,12 +315,14 @@ static void print_usage(void) {
}

static int parse_record_args(int cmdi, int argc, char** argv, Flags* flags) {
struct option opts[] = { { "force-syscall-buffer", no_argument, NULL, 'b' },
{ "ignore-signal", required_argument, NULL, 'i' },
{ "num-cpu-ticks", required_argument, NULL, 'c' },
{ "num-events", required_argument, NULL, 'e' },
{ "no-syscall-buffer", no_argument, NULL, 'n' },
{ 0 } };
struct option opts[] = {
{ "force-syscall-buffer", no_argument, nullptr, 'b' },
{ "ignore-signal", required_argument, nullptr, 'i' },
{ "num-cpu-ticks", required_argument, nullptr, 'c' },
{ "num-events", required_argument, nullptr, 'e' },
{ "no-syscall-buffer", no_argument, nullptr, 'n' },
{ 0 }
};
optind = cmdi;
while (1) {
int i = 0;
Expand Down Expand Up @@ -349,13 +351,13 @@ static int parse_record_args(int cmdi, int argc, char** argv, Flags* flags) {
}

static int parse_replay_args(int cmdi, int argc, char** argv, Flags* flags) {
struct option opts[] = { { "autopilot", no_argument, NULL, 'a' },
{ "dbgport", required_argument, NULL, 's' },
{ "goto", required_argument, NULL, 'g' },
{ "no-redirect-output", no_argument, NULL, 'q' },
{ "onfork", required_argument, NULL, 'f' },
{ "onprocess", required_argument, NULL, 'p' },
{ "gdb-x", required_argument, NULL, 'x' },
struct option opts[] = { { "autopilot", no_argument, nullptr, 'a' },
{ "dbgport", required_argument, nullptr, 's' },
{ "goto", required_argument, nullptr, 'g' },
{ "no-redirect-output", no_argument, nullptr, 'q' },
{ "onfork", required_argument, nullptr, 'f' },
{ "onprocess", required_argument, nullptr, 'p' },
{ "gdb-x", required_argument, nullptr, 'x' },
{ 0 } };
optind = cmdi;
while (1) {
Expand Down Expand Up @@ -395,9 +397,9 @@ static int parse_replay_args(int cmdi, int argc, char** argv, Flags* flags) {
}

static int parse_dump_args(int cmdi, int argc, char** argv, Flags* flags) {
struct option opts[] = { { "syscallbuf", no_argument, NULL, 'b' },
{ "raw", no_argument, NULL, 'r' },
{ "statistics", no_argument, NULL, 's' },
struct option opts[] = { { "syscallbuf", no_argument, nullptr, 'b' },
{ "raw", no_argument, nullptr, 'r' },
{ "statistics", no_argument, nullptr, 's' },
{ 0 } };
optind = cmdi;
while (1) {
Expand All @@ -421,20 +423,21 @@ static int parse_dump_args(int cmdi, int argc, char** argv, Flags* flags) {
}

static int parse_common_args(int argc, char** argv, Flags* flags) {
struct option opts[] = { { "checksum", required_argument, NULL, 'c' },
{ "check-cached-mmaps", no_argument, NULL, 'k' },
{ "cpu-unbound", no_argument, NULL, 'u' },
{ "dump-at", required_argument, NULL, 't' },
{ "dump-on", required_argument, NULL, 'd' },
{ "force-things", no_argument, NULL, 'f' },
{ "force-microarch", required_argument, NULL, 'a' },
{ "mark-stdio", no_argument, NULL, 'm' },
{ "suppress-environment-warnings", no_argument,
NULL, 's' },
{ "fatal-errors", no_argument, NULL, 'e' },
{ "verbose", no_argument, NULL, 'v' },
{ "wait-secs", required_argument, NULL, 'w' },
{ 0 } };
struct option opts[] = {
{ "checksum", required_argument, nullptr, 'c' },
{ "check-cached-mmaps", no_argument, nullptr, 'k' },
{ "cpu-unbound", no_argument, nullptr, 'u' },
{ "dump-at", required_argument, nullptr, 't' },
{ "dump-on", required_argument, nullptr, 'd' },
{ "force-things", no_argument, nullptr, 'f' },
{ "force-microarch", required_argument, nullptr, 'a' },
{ "mark-stdio", no_argument, nullptr, 'm' },
{ "suppress-environment-warnings", no_argument, nullptr, 's' },
{ "fatal-errors", no_argument, nullptr, 'e' },
{ "verbose", no_argument, nullptr, 'v' },
{ "wait-secs", required_argument, nullptr, 'w' },
{ 0 }
};
while (1) {
int i = 0;
switch (getopt_long(argc, argv, "+a:c:d:fkmst:uvw:", opts, &i)) {
Expand Down Expand Up @@ -541,7 +544,7 @@ static int parse_args(int argc, char** argv, Flags* flags, Command* command) {
}

static string find_syscall_buffer_library() {
char* exe_path = realpath("/proc/self/exe", NULL);
char* exe_path = realpath("/proc/self/exe", nullptr);
string lib_path = exe_path;
free(exe_path);

Expand All @@ -561,7 +564,7 @@ static string find_syscall_buffer_library() {

static void init_random() {
// Not very good, but good enough for our non-security-sensitive needs.
srandom(time(NULL) ^ getpid());
srandom(time(nullptr) ^ getpid());
}

int main(int argc, char* argv[]) {
Expand Down
4 changes: 2 additions & 2 deletions src/record_syscall.cc
Expand Up @@ -113,7 +113,7 @@ static void reset_scratch_pointers(Task* t) {
/**
* Record a tracee argument pointer that (most likely) was replaced by
* a pointer into scratch memory. |argp| can have any value,
* including NULL. It must be fetched by calling |pop_arg_ptr()|
* including nullptr. It must be fetched by calling |pop_arg_ptr()|
* during processing syscall results, and in reverse order of calls to
* |push*()|.
*/
Expand Down Expand Up @@ -931,7 +931,7 @@ template <typename Arch> static Switchable rec_prepare_syscall_arch(Task* t) {
if (!need_scratch_setup) {
return ALLOW_SWITCH;
}
/* XXX fds can be NULL, right? */
/* XXX fds can be nullptr, right? */
push_arg_ptr(t, fds);
r.set_arg1(fds2);
scratch += nfds * fds.referent_size();
Expand Down
2 changes: 1 addition & 1 deletion src/record_syscall.h
Expand Up @@ -16,7 +16,7 @@ void rec_before_record_syscall_entry(Task* t, int syscallno);
* Prepare |t| to enter its current syscall event. Return ALLOW_SWITCH if
* a context-switch is allowed for |t|, PREVENT_SWITCH if not.
*
* Set |*kernel_sync_addr| to non-NULL to force waiting on that memory
* Set |*kernel_sync_addr| to non-nullptr to force waiting on that memory
* cell in the child's address space to become |sync_val|. This is an
* overly general mechanism that's used for FUTEX_LOCK_PI. If you're
* not FUTEX_LOCK_PI, you probably shouldn't be using this.
Expand Down
2 changes: 1 addition & 1 deletion src/recorder.cc
Expand Up @@ -842,7 +842,7 @@ static void install_termsig_handlers(void) {
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handle_termsig;
sigaction(termsigs[i], &sa, NULL);
sigaction(termsigs[i], &sa, nullptr);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/recorder_sched.cc
Expand Up @@ -24,7 +24,7 @@
using namespace std;

/**
* The currently scheduled task. This may be NULL if the last scheduled task
* The currently scheduled task. This may be nullptr if the last scheduled task
* has been destroyed.
*/
static Task* current;
Expand Down Expand Up @@ -143,7 +143,7 @@ static Task* find_next_runnable_task(Session& session, bool* by_waitpid) {
same_priority_start = same_priority_end;
}

return NULL;
return nullptr;
}

Task* rec_sched_get_active_thread(RecordSession& session, Task* t,
Expand Down Expand Up @@ -245,9 +245,9 @@ void rec_sched_deregister_thread(Task** t_ptr) {
if (t == current) {
current = get_next_task_with_same_priority(t);
if (t == current) {
current = NULL;
current = nullptr;
}
}
delete t;
*t_ptr = NULL;
*t_ptr = nullptr;
}
8 changes: 4 additions & 4 deletions src/replayer.cc
Expand Up @@ -382,13 +382,13 @@ void dispatch_debugger_request(ReplaySession& session, struct dbg_context* dbg,
target->real_tgid());
ScopedFd fd(filename, O_RDONLY);
if (0 > fd) {
dbg_reply_get_auxv(dbg, NULL, -1);
dbg_reply_get_auxv(dbg, nullptr, -1);
return;
}

len = read(fd, auxv, sizeof(auxv));
if (0 > len) {
dbg_reply_get_auxv(dbg, NULL, -1);
dbg_reply_get_auxv(dbg, nullptr, -1);
return;
}

Expand Down Expand Up @@ -604,7 +604,7 @@ static Task* schedule_task(ReplaySession& session, Task** intr_t,
}

Task* t = session.find_task(session.current_trace_frame().tid());
assert(t != NULL);
assert(t);
ASSERT(t, &session == &t->replay_session());

if (EV_TRACE_TERMINATION == session.current_trace_frame().event().type) {
Expand Down Expand Up @@ -2172,7 +2172,7 @@ static void set_sig_blockedness(int sig, int blockedness) {
sigset_t sset;
sigemptyset(&sset);
sigaddset(&sset, sig);
if (sigprocmask(blockedness, &sset, NULL)) {
if (sigprocmask(blockedness, &sset, nullptr)) {
FATAL() << "Didn't change sigmask.";
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/task.cc
Expand Up @@ -104,7 +104,7 @@ struct Sighandlers {
for (int i = 1; i < ssize_t(array_length(handlers)); ++i) {
Sighandler& h = handlers[i];
struct sigaction act;
if (-1 == sigaction(i, NULL, &act)) {
if (-1 == sigaction(i, nullptr, &act)) {
/* EINVAL means we're querying an
* unused signal number. */
assert(EINVAL == errno);
Expand Down Expand Up @@ -597,7 +597,7 @@ void Task::maybe_update_vm_arch(int syscallno, SyscallEntryOrExit state) {
case Arch::brk: {
remote_ptr<void> addr = r.arg1();
if (!addr) {
// A brk() update of NULL is observed with
// A brk() update of nullptr is observed with
// libc, which apparently is its means of
// finding out the initial brk(). We can
// ignore that for the purposes of updating
Expand Down Expand Up @@ -1803,7 +1803,7 @@ ssize_t Task::read_bytes_ptrace(remote_ptr<void> addr, ssize_t buf_size,
uintptr_t end_word = start_word + word_size;
uintptr_t length = std::min(end_word - start, uintptr_t(buf_size - nread));

long v = fallible_ptrace(PTRACE_PEEKDATA, start_word, NULL);
long v = fallible_ptrace(PTRACE_PEEKDATA, start_word, nullptr);
if (errno) {
break;
}
Expand Down Expand Up @@ -1833,7 +1833,7 @@ ssize_t Task::write_bytes_ptrace(remote_ptr<void> addr, ssize_t buf_size,

long v;
if (length < word_size) {
v = fallible_ptrace(PTRACE_PEEKDATA, start_word, NULL);
v = fallible_ptrace(PTRACE_PEEKDATA, start_word, nullptr);
if (errno) {
break;
}
Expand Down Expand Up @@ -2038,7 +2038,7 @@ bool Task::clone_syscall_is_complete() {
sa.sa_handler = handle_alarm_signal;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0; // No SA_RESTART, so waitpid() will be interrupted
sigaction(SIGALRM, &sa, NULL);
sigaction(SIGALRM, &sa, nullptr);

Task* t = new Task(session, tid, rec_tid, 0);
// The very first task we fork inherits the signal
Expand All @@ -2050,7 +2050,7 @@ bool Task::clone_syscall_is_complete() {
t->sighandlers.swap(sh);
// Don't use the POSIX wrapper, because it doesn't necessarily
// read the entire sigset tracked by the kernel.
if (::syscall(SYS_rt_sigprocmask, SIG_SETMASK, NULL, &t->blocked_sigs,
if (::syscall(SYS_rt_sigprocmask, SIG_SETMASK, nullptr, &t->blocked_sigs,
sizeof(t->blocked_sigs))) {
FATAL() << "Failed to read blocked signals";
}
Expand Down
4 changes: 2 additions & 2 deletions src/task.h
Expand Up @@ -191,7 +191,7 @@ class Task {

/**
* Shortcut to the single |pending_event->desched.rec| when
* there's one desched event on the stack, and NULL otherwise.
* there's one desched event on the stack, and nullptr otherwise.
* Exists just so that clients don't need to dig around in the
* event stack to find this record.
*/
Expand Down Expand Up @@ -267,7 +267,7 @@ class Task {
* Dump attributes of this process, including pending events,
* to |out|, which defaults to LOG_FILE.
*/
void dump(FILE* out = NULL) const;
void dump(FILE* out = nullptr) const;

/**
* Called after the first exec in a session, when the session first
Expand Down

0 comments on commit 1a2f524

Please sign in to comment.