diff --git a/common/lib/advio.cpp b/common/lib/advio.cpp index 6b4d2f28e..2169003f8 100644 --- a/common/lib/advio.cpp +++ b/common/lib/advio.cpp @@ -213,11 +213,11 @@ AFILE * afopen(const char *uri, const char *mode) } else { /* Open local file by prepending file:// schema. */ if (strlen(uri) <= 1) - return NULL; + return nullptr; /* Handle relative paths */ if (uri[0] != '/') { - cwd = getcwd(NULL, 0); + cwd = getcwd(nullptr, 0); af->uri = strf("file://%s/%s", cwd, uri); @@ -266,7 +266,7 @@ out1: fclose(af->file); out2: free(af->uri); free(af); - return NULL; + return nullptr; } int afclose(AFILE *af) diff --git a/common/lib/buffer.cpp b/common/lib/buffer.cpp index 075476dff..486555d90 100644 --- a/common/lib/buffer.cpp +++ b/common/lib/buffer.cpp @@ -72,7 +72,7 @@ int buffer_append(struct buffer *b, const char *data, size_t len) int buffer_parse_json(struct buffer *b, json_t **j) { - *j = json_loadb(b->buf, b->len, 0, NULL); + *j = json_loadb(b->buf, b->len, 0, nullptr); if (!*j) return -1; diff --git a/common/lib/common.cpp b/common/lib/common.cpp index 015df1734..e5f527e0a 100644 --- a/common/lib/common.cpp +++ b/common/lib/common.cpp @@ -65,6 +65,6 @@ const char * state_print(enum state s) break; default: - return NULL; + return nullptr; } } diff --git a/common/lib/kernel/kernel.cpp b/common/lib/kernel/kernel.cpp index c81324b2a..28ee836e1 100644 --- a/common/lib/kernel/kernel.cpp +++ b/common/lib/kernel/kernel.cpp @@ -64,7 +64,7 @@ int kernel_get_cacheline_size() #elif defined(__MACH__) /* Open the command for reading. */ FILE *fp = popen("sysctl -n machdep.cpu.cache.linesize", "r"); - if (fp == NULL) + if (fp == nullptr) return -1; int ret, size; @@ -92,7 +92,7 @@ int kernel_get_page_size() int kernel_get_hugepage_size() { #ifdef __linux__ - char *key, *value, *unit, *line = NULL, *lasts; + char *key, *value, *unit, *line = nullptr, *lasts; int sz = -1; size_t len = 0; FILE *f; @@ -103,11 +103,11 @@ int kernel_get_hugepage_size() while (getline(&line, &len, f) != -1) { key = strtok_r(line, ": ", &lasts); - value = strtok_r(NULL, " ", &lasts); - unit = strtok_r(NULL, "\n", &lasts); + value = strtok_r(nullptr, " ", &lasts); + unit = strtok_r(nullptr, "\n", &lasts); if (!strcmp(key, "Hugepagesize") && !strcmp(unit, "kB")) { - sz = strtoul(value, NULL, 10) * 1024; + sz = strtoul(value, nullptr, 10) * 1024; break; } } @@ -174,7 +174,7 @@ int kernel_module_loaded(const char *module) { FILE *f; int ret = -1; - char *line = NULL; + char *line = nullptr; size_t len = 0; f = fopen(PROCFS_PATH "/modules", "r"); @@ -222,7 +222,7 @@ int kernel_get_cmdline_param(const char *param, char *buf, size_t len) return 0; /* found */ } } - } while ((tok = strtok_r(NULL, " \t", &lasts))); + } while ((tok = strtok_r(nullptr, " \t", &lasts))); out: fclose(f); @@ -285,7 +285,7 @@ int kernel_irq_setaffinity(unsigned irq, uintmax_t aff, uintmax_t *old) int kernel_get_cpu_frequency(uint64_t *freq) { - char *line = NULL, *sep, *end; + char *line = nullptr, *sep, *end; size_t len = 0; double dfreq; int ret; diff --git a/common/lib/kernel/pci.cpp b/common/lib/kernel/pci.cpp index 21a75e1a9..6485b828c 100644 --- a/common/lib/kernel/pci.cpp +++ b/common/lib/kernel/pci.cpp @@ -44,7 +44,7 @@ int pci_init(struct pci *p) snprintf(path, sizeof(path), "%s/bus/pci/devices", SYSFS_PATH); dp = opendir(path); - if (dp == NULL) { + if (dp == nullptr) { serror("Failed to detect PCI devices"); return -1; } @@ -92,7 +92,7 @@ int pci_init(struct pci *p) int pci_destroy(struct pci *p) { - vlist_destroy(&p->devices, NULL, true); + vlist_destroy(&p->devices, nullptr, true); return 0; } @@ -258,7 +258,7 @@ size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions) FILE* f; char sysfs[1024]; - assert(regions != NULL); + assert(regions != nullptr); snprintf(sysfs, sizeof(sysfs), "%s/bus/pci/devices/%04x:%02x:%02x.%x/resource", SYSFS_PATH, d->slot.domain, d->slot.bus, d->slot.device, d->slot.function); @@ -272,7 +272,7 @@ size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions) size_t valid_regions = 0; ssize_t bytesRead; - char* line = NULL; + char* line = nullptr; size_t len = 0; int region = 0; @@ -295,7 +295,7 @@ size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions) free(line); /* Required for getline() to allocate a new buffer on the next iteration. */ - line = NULL; + line = nullptr; len = 0; if (tokens[0] != tokens[1]) { diff --git a/common/lib/kernel/vfio_legacy.cpp b/common/lib/kernel/vfio_legacy.cpp index 1de31ba17..d06c86efc 100644 --- a/common/lib/kernel/vfio_legacy.cpp +++ b/common/lib/kernel/vfio_legacy.cpp @@ -241,7 +241,7 @@ int vfio_pci_attach(struct vfio_device *d, struct vfio_container *c, struct pci_ int vfio_device_attach(struct vfio_device *d, struct vfio_container *c, const char *name, int index) { int ret; - struct vfio_group *g = NULL; + struct vfio_group *g = nullptr; /* Check if group already exists */ for (size_t i = 0; i < vlist_length(&c->groups); i++) { @@ -375,7 +375,7 @@ int vfio_pci_msi_find(struct vfio_device *d, int nos[32]) /* Find last column of line */ do { last = col; - } while ((col = strtok_r(NULL, " ", &lasts))); + } while ((col = strtok_r(nullptr, " ", &lasts))); ret = sscanf(last, "vfio-msi[%u](%12[0-9:])", &idx, name); @@ -547,7 +547,7 @@ void * vfio_map_region(struct vfio_device *d, int idx) if (!(r->flags & VFIO_REGION_INFO_FLAG_MMAP)) return MAP_FAILED; - d->mappings[idx] = mmap(NULL, r->size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_32BIT, d->fd, r->offset); + d->mappings[idx] = mmap(nullptr, r->size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_32BIT, d->fd, r->offset); return d->mappings[idx]; } @@ -566,7 +566,7 @@ int vfio_unmap_region(struct vfio_device *d, int idx) if (ret) return -2; - d->mappings[idx] = NULL; + d->mappings[idx] = nullptr; return 0; } diff --git a/common/lib/list.cpp b/common/lib/list.cpp index 02f2d21dc..355f74ee3 100644 --- a/common/lib/list.cpp +++ b/common/lib/list.cpp @@ -57,11 +57,11 @@ int vlist_init(struct vlist *l) { assert(l->state == STATE_DESTROYED); - pthread_mutex_init(&l->lock, NULL); + pthread_mutex_init(&l->lock, nullptr); l->length = 0; l->capacity = 0; - l->array = NULL; + l->array = nullptr; l->state = STATE_INITIALIZED; return 0; @@ -86,7 +86,7 @@ int vlist_destroy(struct vlist *l, dtor_cb_t destructor, bool release) l->length = -1; l->capacity = 0; - l->array = NULL; + l->array = nullptr; l->state = STATE_DESTROYED; pthread_mutex_unlock(&l->lock); @@ -238,7 +238,7 @@ void * vlist_search(struct vlist *l, cmp_cb_t cmp, void *ctx) goto out; } - e = NULL; /* not found */ + e = nullptr; /* not found */ out: pthread_mutex_unlock(&l->lock); diff --git a/common/lib/task.cpp b/common/lib/task.cpp index a20d26f63..eb71bdac3 100644 --- a/common/lib/task.cpp +++ b/common/lib/task.cpp @@ -80,7 +80,7 @@ int task_set_next(struct task *t, struct timespec *next) .it_value = t->next }; - ret = timerfd_settime(t->fd, TFD_TIMER_ABSTIME, &its, NULL); + ret = timerfd_settime(t->fd, TFD_TIMER_ABSTIME, &its, nullptr); if (ret) return ret; #endif /* PERIODIC_TASK_IMPL == TIMERFD */ @@ -113,7 +113,7 @@ int task_set_rate(struct task *t, double rate) .it_value = t->period }; - ret = timerfd_settime(t->fd, 0, &its, NULL); + ret = timerfd_settime(t->fd, 0, &its, nullptr); if (ret) return ret; #endif /* PERIODIC_TASK_IMPL */ @@ -148,7 +148,7 @@ uint64_t task_wait(struct task *t) #if PERIODIC_TASK_IMPL == CLOCK_NANOSLEEP do { - ret = clock_nanosleep(t->clock, TIMER_ABSTIME, &t->next, NULL); + ret = clock_nanosleep(t->clock, TIMER_ABSTIME, &t->next, nullptr); } while (ret == EINTR); #elif PERIODIC_TASK_IMPL == NANOSLEEP struct timespec req, rem = time_diff(&now, &t->next); diff --git a/common/lib/tsc.cpp b/common/lib/tsc.cpp index c4805821a..d1caf2289 100644 --- a/common/lib/tsc.cpp +++ b/common/lib/tsc.cpp @@ -59,8 +59,8 @@ int tsc_init(struct tsc *t) /** @todo: machdep.tsc.frequency seems to be a measured frequency (based on local APIC? * We should figure out which frequency is more accurate */ -// ret = sysctlbyname("hw.cpufrequency", &frequency, &lenp, NULL, 0); - ret = sysctlbyname("machdep.tsc.frequency", &frequency, &lenp, NULL, 0); +// ret = sysctlbyname("hw.cpufrequency", &frequency, &lenp, nullptr, 0); + ret = sysctlbyname("machdep.tsc.frequency", &frequency, &lenp, nullptr, 0); if (ret) return ret; diff --git a/common/lib/utils.cpp b/common/lib/utils.cpp index d4e6b0050..c7610f161 100644 --- a/common/lib/utils.cpp +++ b/common/lib/utils.cpp @@ -234,7 +234,7 @@ char * vstrcatf(char **dest, const char *fmt, va_list ap) int i = vasprintf(&tmp, fmt, ap); *dest = (char *)(realloc(*dest, n + i + 1)); - if (*dest != NULL) + if (*dest != nullptr) strncpy(*dest+n, tmp, i + 1); free(tmp); @@ -244,7 +244,7 @@ char * vstrcatf(char **dest, const char *fmt, va_list ap) char * strf(const char *fmt, ...) { - char *buf = NULL; + char *buf = nullptr; va_list ap; va_start(ap, fmt); @@ -256,7 +256,7 @@ char * strf(const char *fmt, ...) char * vstrf(const char *fmt, va_list va) { - char *buf = NULL; + char *buf = nullptr; vstrcatf(&buf, fmt, va);