From 1a2f52484f5b3aa55315beeb2178358bb01eeeca Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Mon, 13 Oct 2014 06:44:33 -0700 Subject: [PATCH] Use nullptr instead of NULL. --- src/AddressSpace.cc | 2 +- src/AutoRemoteSyscalls.cc | 2 +- src/CompressedWriter.cc | 10 +++--- src/Session.h | 4 +-- src/debugger_gdb.cc | 8 ++--- src/debugger_gdb.h | 2 +- src/main.cc | 67 ++++++++++++++++++++------------------- src/record_syscall.cc | 4 +-- src/record_syscall.h | 2 +- src/recorder.cc | 2 +- src/recorder_sched.cc | 8 ++--- src/replayer.cc | 8 ++--- src/task.cc | 12 +++---- src/task.h | 4 +-- src/util.cc | 8 ++--- 15 files changed, 71 insertions(+), 72 deletions(-) diff --git a/src/AddressSpace.cc b/src/AddressSpace.cc index 475fcec318..320d8666a9 100644 --- a/src/AddressSpace.cc +++ b/src/AddressSpace.cc @@ -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); } diff --git a/src/AutoRemoteSyscalls.cc b/src/AutoRemoteSyscalls.cc index 4ae1202486..5483e623d9 100644 --- a/src/AutoRemoteSyscalls.cc +++ b/src/AutoRemoteSyscalls.cc @@ -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"; } diff --git a/src/CompressedWriter.cc b/src/CompressedWriter.cc index e25501417c..7e623447d3 100644 --- a/src/CompressedWriter.cc +++ b/src/CompressedWriter.cc @@ -19,7 +19,7 @@ using namespace std; void* CompressedWriter::compression_thread_callback(void* p) { static_cast(p)->compression_thread(); - return NULL; + return nullptr; } CompressedWriter::CompressedWriter(const string& filename, size_t block_size, @@ -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; @@ -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 @@ -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(); diff --git a/src/Session.h b/src/Session.h index d2326407e4..69e53356ae 100644 --- a/src/Session.h +++ b/src/Session.h @@ -71,10 +71,10 @@ class Session { std::shared_ptr 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); diff --git a/src/debugger_gdb.cc b/src/debugger_gdb.cc index 0ac24fa5ff..b65839e233 100644 --- a/src/debugger_gdb.cc +++ b/src/debugger_gdb.cc @@ -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 ... */ @@ -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; @@ -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] || @@ -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; } diff --git a/src/debugger_gdb.h b/src/debugger_gdb.h index 033106f329..f970650572 100644 --- a/src/debugger_gdb.h +++ b/src/debugger_gdb.h @@ -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); diff --git a/src/main.cc b/src/main.cc index 47d598c91f..7990a02202 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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; @@ -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) { @@ -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) { @@ -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)) { @@ -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); @@ -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[]) { diff --git a/src/record_syscall.cc b/src/record_syscall.cc index f1a5377c03..6f1cc89e01 100644 --- a/src/record_syscall.cc +++ b/src/record_syscall.cc @@ -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*()|. */ @@ -931,7 +931,7 @@ template 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(); diff --git a/src/record_syscall.h b/src/record_syscall.h index 01c2a85659..06f8131ca3 100644 --- a/src/record_syscall.h +++ b/src/record_syscall.h @@ -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. diff --git a/src/recorder.cc b/src/recorder.cc index cfab9f6e91..b725f4791e 100644 --- a/src/recorder.cc +++ b/src/recorder.cc @@ -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); } } diff --git a/src/recorder_sched.cc b/src/recorder_sched.cc index 6099ebd55a..5c7a816d69 100644 --- a/src/recorder_sched.cc +++ b/src/recorder_sched.cc @@ -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; @@ -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, @@ -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; } diff --git a/src/replayer.cc b/src/replayer.cc index c4e98f1b38..b214bd9f0f 100644 --- a/src/replayer.cc +++ b/src/replayer.cc @@ -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; } @@ -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) { @@ -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."; } } diff --git a/src/task.cc b/src/task.cc index bd1a153247..2a0e457485 100644 --- a/src/task.cc +++ b/src/task.cc @@ -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); @@ -597,7 +597,7 @@ void Task::maybe_update_vm_arch(int syscallno, SyscallEntryOrExit state) { case Arch::brk: { remote_ptr 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 @@ -1803,7 +1803,7 @@ ssize_t Task::read_bytes_ptrace(remote_ptr 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; } @@ -1833,7 +1833,7 @@ ssize_t Task::write_bytes_ptrace(remote_ptr 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; } @@ -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 @@ -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"; } diff --git a/src/task.h b/src/task.h index 14bf82f079..b8c7c26d50 100644 --- a/src/task.h +++ b/src/task.h @@ -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. */ @@ -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 diff --git a/src/util.cc b/src/util.cc index 0e0914c9ad..568b71fe34 100644 --- a/src/util.cc +++ b/src/util.cc @@ -255,7 +255,7 @@ void print_process_state(pid_t tid) { fflush(stdout); bzero(path, 64); sprintf(path, "/proc/%d/status", tid); - if ((file = fopen(path, "r")) == NULL) { + if ((file = fopen(path, "r")) == nullptr) { perror("error reading child memory status\n"); } @@ -514,10 +514,6 @@ static void iterate_checksums(Task* t, ChecksumMode mode, int global_time) { sizeof(struct syscallbuf_record); } - /* If this segment was filtered, then data->mem_len will be 0 - * to indicate nothing was read. And data->mem will be NULL - * to double-check that. In that case, the checksum will just - * be 0. */ ASSERT(t, buf || valid_mem_len == 0); for (i = 0; i < ssize_t(valid_mem_len / sizeof(*buf)); ++i) { checksum += buf[i]; @@ -992,7 +988,7 @@ static const uint8_t x86_vsyscall_monkeypatch[] = { 0x50, // push %eax 0xb8, 0x00, 0x00, 0x00, 0x00, // mov $_vsyscall_hook_trampoline, %eax // The immediate param of the |mov| is filled in dynamically - // by the template mechanism below. The NULL here is a + // by the template mechanism below. The null bytes here are a // placeholder. 0xff, 0xe0, // jmp *%eax };