Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,-clang-analyzer-optin.performance.Padding'
HeaderFilterRegex: 'src/.*|unittest/.*'
CheckOptions:
+ - key: readability-braces-around-statements.ShortStatementLines
+ value: 1
...
// Array for storing -arch options.
static constexpr int max_arch_args = 10;
size_t arch_args_size = 0;
- char* arch_args[max_arch_args] = {NULL};
+ char* arch_args[max_arch_args] = {nullptr};
// Relocating debuginfo in the format old=new.
char** debug_prefix_maps = nullptr;
Config::visit_items(const ItemVisitor& item_visitor) const
{
std::vector<std::string> keys;
+ keys.reserve(k_config_key_table.size());
+
for (const auto& item : k_config_key_table) {
keys.emplace_back(item.first);
}
{
template<typename ParseContext>
constexpr auto
- parse(ParseContext& ctx) -> decltype(ctx.begin())
+ parse(ParseContext& ctx) const -> decltype(ctx.begin())
{
return ctx.begin();
}
struct args* args = (struct args*)x_malloc(sizeof(struct args));
args->argc = 0;
args->argv = (char**)x_malloc(sizeof(char*));
- args->argv[0] = NULL;
+ args->argv[0] = nullptr;
for (int i = 0; i < init_argc; i++) {
args_add(args, init_args[i]);
}
{
char* p = x_strdup(command);
char* q = p;
- char *word, *saveptr = NULL;
- struct args* args = args_init(0, NULL);
+ char *word, *saveptr = nullptr;
+ struct args* args = args_init(0, nullptr);
while ((word = strtok_r(q, " \t\r\n", &saveptr))) {
args_add(args, word);
- q = NULL;
+ q = nullptr;
}
free(p);
{
char* argtext;
if (!(argtext = read_text_file(filename, 0))) {
- return NULL;
+ return nullptr;
}
- struct args* args = args_init(0, NULL);
+ struct args* args = args_init(0, nullptr);
char* pos = argtext;
char* argbuf = static_cast<char*>(x_malloc(strlen(argtext) + 1));
char* argpos = argbuf;
args->argv = (char**)x_realloc(args->argv, (args->argc + 2) * sizeof(char*));
args->argv[args->argc] = x_strdup(s);
args->argc++;
- args->argv[args->argc] = NULL;
+ args->argv[args->argc] = nullptr;
}
// Add all arguments in to_append to args.
while (n--) {
args->argc--;
free(args->argv[args->argc]);
- args->argv[args->argc] = NULL;
+ args->argv[args->argc] = nullptr;
}
}
};
// Temporary files to remove at program exit.
-static struct pending_tmp_file* pending_tmp_files = NULL;
+static struct pending_tmp_file* pending_tmp_files = nullptr;
// How often (in seconds) to scan $CCACHE_DIR/tmp for left-over temporary
// files.
return;
}
- struct args* prefix = args_init(0, NULL);
+ struct args* prefix = args_init(0, nullptr);
char* e = x_strdup(prefix_command);
- char* saveptr = NULL;
+ char* saveptr = nullptr;
for (char* tok = strtok_r(e, " ", &saveptr); tok;
- tok = strtok_r(NULL, " ", &saveptr)) {
+ tok = strtok_r(nullptr, " ", &saveptr)) {
char* p;
p = find_executable(ctx, tok, MYNAME);
static const char*
temp_dir(const Context& ctx)
{
- static const char* path = NULL;
+ static const char* path = nullptr;
if (path) {
return path; // Memoize
}
}
void
-block_signals(void)
+block_signals()
{
#ifndef _WIN32
- sigprocmask(SIG_BLOCK, &fatal_signal_set, NULL);
+ sigprocmask(SIG_BLOCK, &fatal_signal_set, nullptr);
#endif
}
void
-unblock_signals(void)
+unblock_signals()
{
#ifndef _WIN32
sigset_t empty;
sigemptyset(&empty);
- sigprocmask(SIG_SETMASK, &empty, NULL);
+ sigprocmask(SIG_SETMASK, &empty, nullptr);
#endif
}
}
static void
-do_clean_up_pending_tmp_files(void)
+do_clean_up_pending_tmp_files()
{
struct pending_tmp_file* p = pending_tmp_files;
while (p) {
}
static void
-clean_up_pending_tmp_files(void)
+clean_up_pending_tmp_files()
{
block_signals();
do_clean_up_pending_tmp_files();
// If ccache was killed explicitly, then bring the compiler subprocess (if
// any) with us as well.
if (signum == SIGTERM && compiler_pid != 0
- && waitpid(compiler_pid, NULL, WNOHANG) == 0) {
+ && waitpid(compiler_pid, nullptr, WNOHANG) == 0) {
kill(compiler_pid, signum);
}
if (compiler_pid != 0) {
// Wait for compiler subprocess to exit before we snuff it.
- waitpid(compiler_pid, NULL, 0);
+ waitpid(compiler_pid, nullptr, 0);
}
// Resend signal to ourselves to exit properly after returning from the
# ifdef SA_RESTART
act.sa_flags = SA_RESTART;
# endif
- sigaction(signum, &act, NULL);
+ sigaction(signum, &act, nullptr);
}
static void
-set_up_signal_handlers(void)
+set_up_signal_handlers()
{
sigemptyset(&fatal_signal_set);
sigaddset(&fatal_signal_set, SIGINT);
static void
clean_up_internal_tempdir(const Context& ctx)
{
- time_t now = time(NULL);
+ time_t now = time(nullptr);
auto st = Stat::stat(ctx.config.cache_dir(), Stat::OnError::log);
if (!st || st.mtime() + k_tempdir_cleanup_interval >= now) {
// No cleanup needed.
if (ctx.config.direct_mode()) {
if (!is_pch) { // else: the file has already been hashed.
- char* source = NULL;
+ char* source = nullptr;
size_t size;
if (st.size() > 0) {
if (!read_file(path.c_str(), st.size(), &source, &size)) {
ctx.ignore_headers = nullptr;
ctx.ignore_headers_len = 0;
if (!ctx.config.ignore_headers_in_manifest().empty()) {
- char *header, *p, *q, *saveptr = NULL;
+ char *header, *p, *q, *saveptr = nullptr;
p = x_strdup(ctx.config.ignore_headers_in_manifest().c_str());
q = p;
while ((header = strtok_r(q, PATH_DELIM, &saveptr))) {
ctx.ignore_headers = static_cast<char**>(x_realloc(
ctx.ignore_headers, (ctx.ignore_headers_len + 1) * sizeof(char*)));
ctx.ignore_headers[ctx.ignore_headers_len++] = x_strdup(header);
- q = NULL;
+ q = nullptr;
}
free(p);
}
hash_string_buffer(hash, inc_path, strlen(inc_path));
}
- remember_include_file(ctx, inc_path, hash, system, NULL);
+ remember_include_file(ctx, inc_path, hash, system, nullptr);
free(inc_path);
p = q; // Everything of interest between p and q has been hashed now.
} else if (q[0] == '.' && q[1] == 'i' && q[2] == 'n' && q[3] == 'c'
std::string pch_path =
make_relative_path(ctx, ctx.included_pch_file.c_str());
hash_string(hash, pch_path);
- remember_include_file(ctx, pch_path, hash, false, NULL);
+ remember_include_file(ctx, pch_path, hash, false, nullptr);
}
bool debug_included = getenv("CCACHE_DEBUG_INCLUDED");
if (relpath != token) {
free(relpath);
}
- token = strtok_r(NULL, " \t", &saveptr);
+ token = strtok_r(nullptr, " \t", &saveptr);
}
}
cc_log("Cannot open dependency file %s: %s",
ctx.args_info.output_dep.c_str(),
strerror(errno));
- return NULL;
+ return nullptr;
}
char buf[10000];
char* saveptr;
char* token;
for (token = strtok_r(buf, " \t\n", &saveptr); token;
- token = strtok_r(NULL, " \t\n", &saveptr)) {
+ token = strtok_r(nullptr, " \t\n", &saveptr)) {
if (str_endswith(token, ":") || str_eq(token, "\\")) {
continue;
}
std::string pch_path =
make_relative_path(ctx, ctx.included_pch_file.c_str());
hash_string(hash, pch_path);
- remember_include_file(ctx, pch_path, hash, false, NULL);
+ remember_include_file(ctx, pch_path, hash, false, nullptr);
}
bool debug_included = getenv("CCACHE_DEBUG_INCLUDED");
return false;
}
f << cachedir_tag;
- if (!f) {
- return false;
- }
-
- return true;
+ return static_cast<bool>(f);
}
// Run the real compiler and put the result in cache.
}
add_prefix(ctx, depend_mode_args, ctx.config.prefix_command().c_str());
- ctx.time_of_compilation = time(NULL);
+ ctx.time_of_compilation = time(nullptr);
status = execute(
depend_mode_args->argv, tmp_stdout_fd, tmp_stderr_fd, &compiler_pid);
args_free(depend_mode_args);
static struct digest*
get_result_name_from_cpp(Context& ctx, struct args* args, struct hash* hash)
{
- ctx.time_of_compilation = time(NULL);
+ ctx.time_of_compilation = time(nullptr);
- char* path_stderr = NULL;
+ char* path_stderr = nullptr;
char* path_stdout = nullptr;
int status;
if (ctx.args_info.direct_i_file) {
#else
const char* compilers[] = {"gcc", "g++"};
#endif
- for (size_t i = 0; i < ARRAY_SIZE(compilers); i++) {
+ for (const char* compiler : compilers) {
if (ccbin) {
- char* path = format("%s/%s", ccbin, compilers[i]);
+ char* path = format("%s/%s", ccbin, compiler);
auto st = Stat::stat(path);
if (st) {
hash_compiler(ctx, hash, st, path, false);
}
free(path);
} else {
- char* path = find_executable(ctx, compilers[i], MYNAME);
+ char* path = find_executable(ctx, compiler, MYNAME);
if (path) {
auto st = Stat::stat(path, Stat::OnError::log);
hash_compiler(ctx, hash, st, ccbin, false);
if (!(ctx.config.sloppiness() & SLOPPY_LOCALE)) {
// Hash environment variables that may affect localization of compiler
// warning messages.
- const char* envvars[] = {"LANG", "LC_ALL", "LC_CTYPE", "LC_MESSAGES", NULL};
+ const char* envvars[] = {
+ "LANG", "LC_ALL", "LC_CTYPE", "LC_MESSAGES", nullptr};
for (const char** p = envvars; *p; ++p) {
char* v = getenv(*p);
if (v) {
char* p = x_strdup(ctx.config.extra_files_to_hash().c_str());
char* q = p;
char* path;
- char* saveptr = NULL;
+ char* saveptr = nullptr;
while ((path = strtok_r(q, PATH_DELIM, &saveptr))) {
cc_log("Hashing extra file %s", path);
hash_delimiter(hash, "extrafile");
if (!hash_file(hash, path)) {
failed(STATS_BADEXTRAFILE);
}
- q = NULL;
+ q = nullptr;
}
free(p);
}
}
}
- char* p = NULL;
+ char* p = nullptr;
if (str_startswith(args->argv[i], "-specs=")) {
p = args->argv[i] + 7;
} else if (str_startswith(args->argv[i], "--specs=")) {
}
if (!found_ccbin && ctx.args_info.actual_language == "cu") {
- hash_nvcc_host_compiler(ctx, hash, NULL, NULL);
+ hash_nvcc_host_compiler(ctx, hash, nullptr, nullptr);
}
// For profile generation (-fprofile-arcs, -fprofile-generate):
hash_string(hash, ctx.args_info.arch_args[i]);
}
- struct digest* result_name = NULL;
+ struct digest* result_name = nullptr;
if (direct_mode) {
// Hash environment variables that affect the preprocessor output.
const char* envvars[] = {"CPATH",
"CPLUS_INCLUDE_PATH",
"OBJC_INCLUDE_PATH",
"OBJCPLUS_INCLUDE_PATH", // clang
- NULL};
+ nullptr};
for (const char** p = envvars; *p; ++p) {
char* v = getenv(*p);
if (v) {
if (result & HASH_SOURCE_CODE_FOUND_TIME) {
cc_log("Disabling direct mode");
ctx.config.set_direct_mode(false);
- return NULL;
+ return nullptr;
}
char manifest_name_string[DIGEST_STRING_BUFFER_SIZE];
ctx.args_info.arch_args[i]);
if (i != ctx.args_info.arch_args_size - 1) {
free(result_name);
- result_name = NULL;
+ result_name = nullptr;
}
args_pop(preprocessor_args, 1);
}
}
static bool
-color_output_possible(void)
+color_output_possible()
{
const char* term_env = getenv("TERM");
return isatty(STDERR_FILENO) && term_env && strcasecmp(term_env, "DUMB") != 0;
detect_pch(Context& ctx, const char* option, const char* arg, bool* found_pch)
{
// Try to be smart about detecting precompiled headers.
- char* pch_file = NULL;
+ char* pch_file = nullptr;
if (str_eq(option, "-include-pch") || str_eq(option, "-include-pth")) {
if (Stat::stat(arg)) {
cc_log("Detected use of precompiled header: %s", arg);
// * those that only should be passed to the preprocessor (if run_second_cpp
// is false), and
// * dependency options (like -MD and friends).
- struct args* common_args = args_init(0, NULL);
+ struct args* common_args = args_init(0, nullptr);
ArgsScopeGuard common_args_guard(common_args);
// cpp_args contains arguments that were not added to common_args, i.e. those
// that should only be passed to the preprocessor if run_second_cpp is false.
// If run_second_cpp is true, they will be passed to the compiler as well.
- struct args* cpp_args = args_init(0, NULL);
+ struct args* cpp_args = args_init(0, nullptr);
ArgsScopeGuard cpp_args_guard(cpp_args);
// dep_args contains dependency options like -MD. They are only passed to the
// preprocessor, never to the compiler.
- struct args* dep_args = args_init(0, NULL);
+ struct args* dep_args = args_init(0, nullptr);
ArgsScopeGuard dep_args_guard(dep_args);
// compiler_only_args contains arguments that should only be passed to the
// compiler, not the preprocessor.
- struct args* compiler_only_args = args_init(0, NULL); // will leak on failure
+ struct args* compiler_only_args =
+ args_init(0, nullptr); // will leak on failure
bool found_color_diagnostics = false;
bool found_directives_only = false;
// Need to dump log buffer as the last exit function to not lose any logs.
exitfn_add_last(dump_debug_log_buffer_exitfn, &ctx);
- FILE* debug_text_file = NULL;
+ FILE* debug_text_file = nullptr;
if (ctx.config.debug()) {
std::string path =
fmt::format("{}.ccache-input-text", ctx.args_info.output_obj);
args_extend(args_to_hash, extra_args_to_hash);
bool put_result_in_manifest = false;
- struct digest* result_name = NULL;
- struct digest* result_name_from_manifest = NULL;
+ struct digest* result_name = nullptr;
+ struct digest* result_name_from_manifest = nullptr;
if (ctx.config.direct_mode()) {
cc_log("Trying direct lookup");
MTR_BEGIN("hash", "direct_hash");
add_prefix(ctx, compiler_args, ctx.config.prefix_command().c_str());
// In depend_mode, extend the direct hash.
- struct hash* depend_mode_hash = ctx.config.depend_mode() ? direct_hash : NULL;
+ struct hash* depend_mode_hash =
+ ctx.config.depend_mode() ? direct_hash : nullptr;
// Run real compiler, sending output to cache.
MTR_BEGIN("cache", "to_cache");
PRINT_STATS,
};
static const struct option options[] = {
- {"cleanup", no_argument, 0, 'c'},
- {"clear", no_argument, 0, 'C'},
- {"dump-manifest", required_argument, 0, DUMP_MANIFEST},
- {"dump-result", required_argument, 0, DUMP_RESULT},
- {"get-config", required_argument, 0, 'k'},
- {"hash-file", required_argument, 0, HASH_FILE},
- {"help", no_argument, 0, 'h'},
- {"max-files", required_argument, 0, 'F'},
- {"max-size", required_argument, 0, 'M'},
- {"print-stats", no_argument, 0, PRINT_STATS},
- {"recompress", required_argument, 0, 'X'},
- {"set-config", required_argument, 0, 'o'},
- {"show-compression", no_argument, 0, 'x'},
- {"show-config", no_argument, 0, 'p'},
- {"show-stats", no_argument, 0, 's'},
- {"version", no_argument, 0, 'V'},
- {"zero-stats", no_argument, 0, 'z'},
- {0, 0, 0, 0}};
+ {"cleanup", no_argument, nullptr, 'c'},
+ {"clear", no_argument, nullptr, 'C'},
+ {"dump-manifest", required_argument, nullptr, DUMP_MANIFEST},
+ {"dump-result", required_argument, nullptr, DUMP_RESULT},
+ {"get-config", required_argument, nullptr, 'k'},
+ {"hash-file", required_argument, nullptr, HASH_FILE},
+ {"help", no_argument, nullptr, 'h'},
+ {"max-files", required_argument, nullptr, 'F'},
+ {"max-size", required_argument, nullptr, 'M'},
+ {"print-stats", no_argument, nullptr, PRINT_STATS},
+ {"recompress", required_argument, nullptr, 'X'},
+ {"set-config", required_argument, nullptr, 'o'},
+ {"show-compression", no_argument, nullptr, 'x'},
+ {"show-config", no_argument, nullptr, 'p'},
+ {"show-stats", no_argument, nullptr, 's'},
+ {"version", no_argument, nullptr, 'V'},
+ {"zero-stats", no_argument, nullptr, 'z'},
+ {nullptr, 0, nullptr, 0}};
Context& ctx = initialize(argc, argv);
(void)ctx;
int c;
- while ((c = getopt_long(argc, argv, "cCk:hF:M:po:sVxX:z", options, NULL))
+ while ((c = getopt_long(argc, argv, "cCk:hF:M:po:sVxX:z", options, nullptr))
!= -1) {
switch (c) {
case DUMP_MANIFEST:
break;
case 'F': { // --max-files
- ctx.config.set_value_in_file(
+ Config::set_value_in_file(
ctx.config.primary_config_path(), "max_files", optarg);
unsigned files = atoi(optarg);
if (files == 0) {
if (!parse_size_with_suffix(optarg, &size)) {
fatal("invalid size: %s", optarg);
}
- ctx.config.set_value_in_file(
+ Config::set_value_in_file(
ctx.config.primary_config_path(), "max_size", optarg);
if (size == 0) {
printf("Unset cache size limit\n");
}
char* key = x_strndup(optarg, p - optarg);
char* value = p + 1;
- ctx.config.set_value_in_file(
- ctx.config.primary_config_path(), key, value);
+ Config::set_value_in_file(ctx.config.primary_config_path(), key, value);
free(key);
break;
}
uint64_t cache_size = 0;
uint32_t files_in_cache = 0;
- time_t current_time = time(NULL);
+ time_t current_time = time(nullptr);
for (size_t i = 0; i < files.size();
++i, progress_receiver(1.0 / 3 + 1.0 * i / files.size() / 3)) {
}
// Used by unittest/test_compopt.c.
-bool compopt_verify_sortedness_and_flags(void);
+bool compopt_verify_sortedness_and_flags();
// For test purposes.
bool
-compopt_verify_sortedness_and_flags(void)
+compopt_verify_sortedness_and_flags()
{
for (size_t i = 0; i < ARRAY_SIZE(compopts); i++) {
if (compopts[i].type & TOO_HARD && compopts[i].type & TAKES_CONCAT_ARG) {
counters_init(size_t initial_size)
{
auto c = static_cast<counters*>(x_malloc(sizeof(counters)));
- c->data = NULL;
+ c->data = nullptr;
c->size = 0;
c->allocated = 0;
counters_resize(c, initial_size);
}
if (!path) {
cc_log("No PATH variable");
- return NULL;
+ return nullptr;
}
return find_executable_in_path(name, exclude_name, path);
// Search the path looking for the first compiler of the right name that
// isn't us.
- char* saveptr = NULL;
+ char* saveptr = nullptr;
for (char* tok = strtok_r(path_buf, PATH_DELIM, &saveptr); tok;
- tok = strtok_r(NULL, PATH_DELIM, &saveptr)) {
+ tok = strtok_r(nullptr, PATH_DELIM, &saveptr)) {
#ifdef _WIN32
char namebuf[MAX_PATH];
int ret = SearchPath(tok, name, NULL, sizeof(namebuf), namebuf, NULL);
}
free(path_buf);
- return NULL;
+ return nullptr;
}
void
struct nullary_exit_function
{
- void (*function)(void);
+ void (*function)();
};
static struct exit_function* exit_functions;
// Initialize exit functions. Must be called once before exitfn_add* are used.
void
-exitfn_init(void)
+exitfn_init()
{
if (atexit(exitfn_call) != 0) {
fatal("atexit failed: %s", strerror(errno));
// Add a nullary function to be called when ccache exits. Functions are called
// in reverse order.
void
-exitfn_add_nullary(void (*function)(void))
+exitfn_add_nullary(void (*function)())
{
auto p = static_cast<exit_function*>(x_malloc(sizeof(exit_function)));
p->function = reinterpret_cast<void (*)(void*)>(function);
auto p = static_cast<exit_function*>(x_malloc(sizeof(exit_function)));
p->function = function;
p->context = context;
- p->next = NULL;
+ p->next = nullptr;
struct exit_function** q = &exit_functions;
while (*q) {
// Call added functions.
void
-exitfn_call(void)
+exitfn_call()
{
struct exit_function* p = exit_functions;
- exit_functions = NULL;
+ exit_functions = nullptr;
while (p) {
p->function(p->context);
struct exit_function* q = p;
p = p->next;
free(q);
}
- if (context_to_clean_up) {
- delete context_to_clean_up;
- }
+
+ delete context_to_clean_up;
}
}
struct hash*
-hash_init(void)
+hash_init()
{
auto hash = static_cast<struct hash*>(malloc(sizeof(struct hash)));
blake2b_init(&hash->state, DIGEST_SIZE);
- hash->debug_binary = NULL;
- hash->debug_text = NULL;
+ hash->debug_binary = nullptr;
+ hash->debug_text = nullptr;
return hash;
}
{
auto result = static_cast<struct hash*>(malloc(sizeof(struct hash)));
result->state = hash->state;
- result->debug_binary = NULL;
- result->debug_text = NULL;
+ result->debug_binary = nullptr;
+ result->debug_text = nullptr;
return result;
}
struct hash;
// Create a new hash state.
-struct hash* hash_init(void);
+struct hash* hash_init();
// Create a new hash state from an existing hash state.
struct hash* hash_copy(struct hash* hash);
// Make sure that the hash sum changes if the (potential) expansion of
// __DATE__ changes.
- time_t t = time(NULL);
+ time_t t = time(nullptr);
struct tm now;
hash_delimiter(hash, "date");
if (!localtime_r(&t, &now)) {
char* command_string = x_strdup(commands);
char* p = command_string;
char* command;
- char* saveptr = NULL;
+ char* saveptr = nullptr;
bool ok = true;
while ((command = strtok_r(p, ";", &saveptr))) {
if (!hash_command_output(hash, command, compiler)) {
ok = false;
}
- p = NULL;
+ p = nullptr;
}
free(command_string);
return ok;
{".tcc", "c++-header"},
{".TCC", "c++-header"},
{".cu", "cu"},
- {NULL, NULL},
+ {nullptr, nullptr},
};
// Supported languages and corresponding preprocessed languages.
{"objective-c++-cpp-output", "objective-c++-cpp-output"},
{"assembler-with-cpp", "assembler"},
{"assembler", "assembler"},
- {NULL, NULL},
+ {nullptr, nullptr},
};
// Guess the language of a file based on its extension. Returns NULL if the
return extensions[i].language;
}
}
- return NULL;
+ return nullptr;
}
// Return the preprocessed language for a given language, or NULL if unknown.
p_language_for_language(const char* language)
{
if (!language) {
- return NULL;
+ return nullptr;
}
for (int i = 0; languages[i].language; ++i) {
if (str_eq(language, languages[i].language)) {
return languages[i].p_language;
}
}
- return NULL;
+ return nullptr;
}
// Return the default file extension (including dot) for a language, or NULL if
extension_for_language(const char* language)
{
if (!language) {
- return NULL;
+ return nullptr;
}
for (int i = 0; extensions[i].extension; i++) {
if (str_eq(language, extensions[i].language)) {
return extensions[i].extension;
}
}
- return NULL;
+ return nullptr;
}
bool
language_is_supported(const char* language)
{
- return p_language_for_language(language) != NULL;
+ return p_language_for_language(language) != nullptr;
}
bool
#ifndef _WIN32
static mode_t
-get_umask(void)
+get_umask()
{
static bool mask_retrieved = false;
static mode_t mask;
}
int dest_fd;
- char* tmp_file = NULL;
+ char* tmp_file = nullptr;
if (via_tmp_file) {
tmp_file = x_strdup(dest);
dest_fd = create_tmp_fd(&tmp_file);
}
int dest_fd;
- char* tmp_file = NULL;
+ char* tmp_file = nullptr;
if (via_tmp_file) {
tmp_file = x_strdup(dest);
dest_fd = create_tmp_fd(&tmp_file);
// Return a static string with the current hostname.
const char*
-get_hostname(void)
+get_hostname()
{
static char hostname[260] = "";
// Return a string to be passed to mkstemp to create a temporary file. Also
// tries to cope with NFS by adding the local hostname.
const char*
-tmp_string(void)
+tmp_string()
{
static char* ret;
if (!ret) {
va_list ap;
va_start(ap, format);
- char* ptr = NULL;
+ char* ptr = nullptr;
if (vasprintf(&ptr, format, ap) == -1) {
fatal("Out of memory in format");
}
if (size == 0) {
// malloc() may return NULL if size is zero, so always do this to make sure
// that the code handles it regardless of platform.
- return NULL;
+ return nullptr;
}
void* ret = malloc(size);
if (!ret) {
reformat(char** ptr, const char* format, ...)
{
char* saved = *ptr;
- *ptr = NULL;
+ *ptr = nullptr;
va_list ap;
va_start(ap, format);
// Return current user's home directory, or NULL if it can't be determined.
const char*
-get_home_directory(void)
+get_home_directory()
{
const char* p = getenv("HOME");
if (p) {
}
}
#endif
- return NULL;
+ return nullptr;
}
// Check whether s1 and s2 have the same executable name.
update_mtime(const char* path)
{
#ifdef HAVE_UTIMES
- utimes(path, NULL);
+ utimes(path, nullptr);
#else
utime(path, NULL);
#endif
if (ret == -1) {
cc_log("Failed reading %s", path);
free(*data);
- *data = NULL;
+ *data = nullptr;
return false;
}
data[size] = '\0';
return data;
} else {
- return NULL;
+ return nullptr;
}
}
subst_env_in_string(const char* str, char** errmsg)
{
assert(errmsg);
- *errmsg = NULL;
+ *errmsg = nullptr;
char* result = x_strdup("");
const char* p = str; // Interval start.
reformat(&result, "%s%.*s", result, (int)(q - p), p);
if (!expand_variable(&q, &result, errmsg)) {
free(result);
- return NULL;
+ return nullptr;
}
p = q + 1;
}
}
double
-time_seconds(void)
+time_seconds()
{
#ifdef HAVE_GETTIMEOFDAY
struct timeval tv;
- gettimeofday(&tv, NULL);
+ gettimeofday(&tv, nullptr);
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
#else
return (double)time(NULL);
lockfile_acquire(const char* path, unsigned staleness_limit)
{
char* lockfile = format("%s.lock", path);
- char* my_content = NULL;
- char* content = NULL;
- char* initial_content = NULL;
+ char* my_content = nullptr;
+ char* content = nullptr;
+ char* initial_content = nullptr;
const char* hostname = get_hostname();
bool acquired = false;
unsigned to_sleep = 1000; // Microseconds.
while (true) {
free(my_content);
- my_content = format("%s:%d:%d", hostname, (int)getpid(), (int)time(NULL));
+ my_content =
+ format("%s:%d:%d", hostname, (int)getpid(), (int)time(nullptr));
#if defined(_WIN32) || defined(__CYGWIN__)
int fd = open(lockfile, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0666);
char timestamp[100];
struct tm tm;
struct timeval tv;
- gettimeofday(&tv, NULL);
+ gettimeofday(&tv, nullptr);
# ifdef __MINGW64_VERSION_MAJOR
localtime_r((time_t*)&tv.tv_sec, &tm);
# else
}
}
-static void warn_log_fail(void) ATTR_NORETURN;
+static void warn_log_fail() ATTR_NORETURN;
// Warn about failure writing to the log file and then exit.
static void
-warn_log_fail(void)
+warn_log_fail()
{
// Note: Can't call fatal() since that would lead to recursion.
fprintf(stderr,
}
std::vector<uint32_t> file_info_indexes;
+ file_info_indexes.reserve(included_files.size());
+
for (const auto& item : included_files) {
file_info_indexes.push_back(get_file_info_index(item.first,
item.second,
{
uint64_t payload_size = 0;
payload_size += 4; // n_files
- for (size_t i = 0; i < mf.files.size(); ++i) {
- payload_size += 2 + mf.files[i].length();
+ for (const auto& file : mf.files) {
+ payload_size += 2 + file.length();
}
payload_size += 4; // n_file_infos
payload_size += mf.file_infos.size() * (4 + DIGEST_SIZE + 8 + 8 + 8);
payload_size += 4; // n_results
- for (size_t i = 0; i < mf.results.size(); ++i) {
+ for (const auto& result : mf.results) {
payload_size += 4; // n_file_info_indexes
- payload_size += mf.results[i].file_info_indexes.size() * 4;
+ payload_size += result.file_info_indexes.size() * 4;
payload_size += DIGEST_SIZE;
}
Compression::level_from_config(config),
payload_size);
writer.write<uint32_t>(mf.files.size());
- for (uint32_t i = 0; i < mf.files.size(); ++i) {
- writer.write<uint16_t>(mf.files[i].length());
- writer.write(mf.files[i].data(), mf.files[i].length());
+ for (const auto& file : mf.files) {
+ writer.write<uint16_t>(file.length());
+ writer.write(file.data(), file.length());
}
writer.write<uint32_t>(mf.file_infos.size());
- for (uint32_t i = 0; i < mf.file_infos.size(); ++i) {
- writer.write<uint32_t>(mf.file_infos[i].index);
- writer.write(mf.file_infos[i].digest.bytes, DIGEST_SIZE);
- writer.write(mf.file_infos[i].fsize);
- writer.write(mf.file_infos[i].mtime);
- writer.write(mf.file_infos[i].ctime);
+ for (const auto& file_info : mf.file_infos) {
+ writer.write<uint32_t>(file_info.index);
+ writer.write(file_info.digest.bytes, DIGEST_SIZE);
+ writer.write(file_info.fsize);
+ writer.write(file_info.mtime);
+ writer.write(file_info.ctime);
}
writer.write<uint32_t>(mf.results.size());
- for (uint32_t i = 0; i < mf.results.size(); ++i) {
- writer.write<uint32_t>(mf.results[i].file_info_indexes.size());
- for (uint32_t j = 0; j < mf.results[i].file_info_indexes.size(); ++j) {
- writer.write(mf.results[i].file_info_indexes[j]);
+ for (const auto& result : mf.results) {
+ writer.write<uint32_t>(result.file_info_indexes.size());
+ for (uint32_t j = 0; j < result.file_info_indexes.size(); ++j) {
+ writer.write(result.file_info_indexes[j]);
}
- writer.write(mf.results[i].name.bytes, DIGEST_SIZE);
+ writer.write(result.name.bytes, DIGEST_SIZE);
}
writer.finalize();
std::unordered_map<std::string, FileStats>& stated_files,
std::unordered_map<std::string, digest>& hashed_files)
{
- for (uint32_t i = 0; i < result.file_info_indexes.size(); ++i) {
- const auto& fi = mf.file_infos[result.file_info_indexes[i]];
+ for (uint32_t file_info_index : result.file_info_indexes) {
+ const auto& fi = mf.file_infos[file_info_index];
const auto& path = mf.files[fi.index];
auto stated_files_iter = stated_files.find(path);
std::unordered_map<std::string, digest> hashed_files;
// Check newest result first since it's a bit more likely to match.
- struct digest* name = NULL;
+ struct digest* name = nullptr;
for (uint32_t i = mf->results.size(); i > 0; i--) {
if (verify_result(
ctx, *mf, mf->results[i - 1], stated_files, hashed_files)) {
char name[DIGEST_STRING_BUFFER_SIZE];
fmt::print(stream, " {}:\n", i);
fmt::print(stream, " File info indexes:");
- for (unsigned j = 0; j < mf->results[i].file_info_indexes.size(); ++j) {
- fmt::print(stream, " {}", mf->results[i].file_info_indexes[j]);
+ for (uint32_t file_info_index : mf->results[i].file_info_indexes) {
+ fmt::print(stream, " {}", file_info_index);
}
fmt::print(stream, "\n");
digest_as_string(&mf->results[i].name, name);
{STATS_CACHEHIT_DIR,
"direct_cache_hit",
"cache hit (direct)",
- NULL,
+ nullptr,
FLAG_ALWAYS},
{STATS_CACHEHIT_CPP,
"preprocessed_cache_hit",
"cache hit (preprocessed)",
- NULL,
+ nullptr,
FLAG_ALWAYS},
- {STATS_CACHEMISS, "cache_miss", "cache miss", NULL, FLAG_ALWAYS},
- {STATS_LINK, "called_for_link", "called for link", NULL, 0},
+ {STATS_CACHEMISS, "cache_miss", "cache miss", nullptr, FLAG_ALWAYS},
+ {STATS_LINK, "called_for_link", "called for link", nullptr, 0},
{STATS_PREPROCESSING,
"called_for_preprocessing",
"called for preprocessing",
- NULL,
+ nullptr,
+ 0},
+ {STATS_MULTIPLE,
+ "multiple_source_files",
+ "multiple source files",
+ nullptr,
0},
- {STATS_MULTIPLE, "multiple_source_files", "multiple source files", NULL, 0},
{STATS_STDOUT,
"compiler_produced_stdout",
"compiler produced stdout",
- NULL,
+ nullptr,
0},
{STATS_NOOUTPUT,
"compiler_produced_no_output",
"compiler produced no output",
- NULL,
+ nullptr,
0},
{STATS_EMPTYOUTPUT,
"compiler_produced_empty_output",
"compiler produced empty output",
- NULL,
+ nullptr,
0},
- {STATS_STATUS, "compile_failed", "compile failed", NULL, 0},
- {STATS_ERROR, "internal_error", "ccache internal error", NULL, 0},
- {STATS_PREPROCESSOR, "preprocessor_error", "preprocessor error", NULL, 0},
+ {STATS_STATUS, "compile_failed", "compile failed", nullptr, 0},
+ {STATS_ERROR, "internal_error", "ccache internal error", nullptr, 0},
+ {STATS_PREPROCESSOR, "preprocessor_error", "preprocessor error", nullptr, 0},
{STATS_CANTUSEPCH,
"could_not_use_precompiled_header",
"can't use precompiled header",
- NULL,
+ nullptr,
+ 0},
+ {STATS_CANTUSEMODULES,
+ "could_not_use_modules",
+ "can't use modules",
+ nullptr,
0},
- {STATS_CANTUSEMODULES, "could_not_use_modules", "can't use modules", NULL, 0},
{STATS_COMPILER,
"could_not_find_compiler",
"couldn't find the compiler",
- NULL,
+ nullptr,
0},
- {STATS_MISSING, "missing_cache_file", "cache file missing", NULL, 0},
- {STATS_ARGS, "bad_compiler_arguments", "bad compiler arguments", NULL, 0},
+ {STATS_MISSING, "missing_cache_file", "cache file missing", nullptr, 0},
+ {STATS_ARGS, "bad_compiler_arguments", "bad compiler arguments", nullptr, 0},
{STATS_SOURCELANG,
"unsupported_source_language",
"unsupported source language",
- NULL,
+ nullptr,
+ 0},
+ {STATS_COMPCHECK,
+ "compiler_check_failed",
+ "compiler check failed",
+ nullptr,
0},
- {STATS_COMPCHECK, "compiler_check_failed", "compiler check failed", NULL, 0},
- {STATS_CONFTEST, "autoconf_test", "autoconf compile/link", NULL, 0},
+ {STATS_CONFTEST, "autoconf_test", "autoconf compile/link", nullptr, 0},
{STATS_UNSUPPORTED_OPTION,
"unsupported_compiler_option",
"unsupported compiler option",
- NULL,
+ nullptr,
0},
{STATS_UNSUPPORTED_DIRECTIVE,
"unsupported_code_directive",
"unsupported code directive",
- NULL,
+ nullptr,
0},
- {STATS_OUTSTDOUT, "output_to_stdout", "output to stdout", NULL, 0},
+ {STATS_OUTSTDOUT, "output_to_stdout", "output to stdout", nullptr, 0},
{STATS_BADOUTPUTFILE,
"bad_output_file",
"could not write to output file",
- NULL,
+ nullptr,
0},
- {STATS_NOINPUT, "no_input_file", "no input file", NULL, 0},
+ {STATS_NOINPUT, "no_input_file", "no input file", nullptr, 0},
{STATS_BADEXTRAFILE,
"error_hashing_extra_file",
"error hashing extra file",
- NULL,
+ nullptr,
0},
{STATS_NUMCLEANUPS,
"cleanups_performed",
"cleanups performed",
- NULL,
+ nullptr,
FLAG_ALWAYS},
{STATS_NUMFILES,
"files_in_cache",
"files in cache",
- NULL,
+ nullptr,
FLAG_NOZERO | FLAG_ALWAYS},
{STATS_TOTALSIZE,
"cache_size_kibibyte",
{STATS_OBSOLETE_MAXFILES,
"OBSOLETE",
"OBSOLETE",
- NULL,
+ nullptr,
FLAG_NOZERO | FLAG_NEVER},
{STATS_OBSOLETE_MAXSIZE,
"OBSOLETE",
"OBSOLETE",
- NULL,
+ nullptr,
FLAG_NOZERO | FLAG_NEVER},
- {STATS_NONE, NULL, NULL, NULL, 0}};
+ {STATS_NONE, nullptr, nullptr, nullptr, 0}};
static char*
format_size(uint64_t size)
strftime(buffer, sizeof(buffer), "%c", &tm);
return format(" %s", buffer);
} else {
- return NULL;
+ return nullptr;
}
}
}
if (!config.log_file().empty() || config.debug()) {
- for (int i = 0; i < STATS_END; ++i) {
- if (updates->data[stats_info[i].stat] != 0
- && !(stats_info[i].flags & FLAG_NOZERO)) {
- cc_log("Result: %s", stats_info[i].message);
+ for (auto& info : stats_info) {
+ if (updates->data[info.stat] != 0 && !(info.flags & FLAG_NOZERO)) {
+ cc_log("Result: %s", info.message);
}
}
}
x_unlink(fname);
free(fname);
- time_t timestamp = time(NULL);
+ time_t timestamp = time(nullptr);
for (int dir = 0; dir <= 0xF; dir++) {
struct counters* counters = counters_init(STATS_END);
int cct_run(const suite_fn* suites, int verbose);
void cct_suite_begin(const char* name);
-void cct_suite_end(void);
+void cct_suite_end();
void cct_test_begin(const char* name);
-void cct_test_end(void);
+void cct_test_end();
void cct_check_passed(const char* file, int line, const char* assertion);
void cct_check_failed(const char* file,
int line,
&suite_legacy_util,
&suite_lockfile,
&suite_stats,
- NULL,
+ nullptr,
};
int
TEST_CASE("Large uncompressible Compression::Type::zstd roundtrip")
{
char data[100000];
- for (size_t i = 0; i < sizeof(data); i++) {
- data[i] = rand() % 256;
+ for (char& c : data) {
+ c = rand() % 256;
}
File f("data.zstd", "wb");
TEST(args_init_empty)
{
- struct args* args = args_init(0, NULL);
+ struct args* args = args_init(0, nullptr);
CHECK(args);
CHECK_INT_EQ(0, args->argc);
CHECK(!args->argv[0]);
struct args *preprocessed, *compiler;
create_file("foo.c", "");
- CHECK(process_args(ctx, orig, &preprocessed, NULL, &compiler)
+ CHECK(process_args(ctx, orig, &preprocessed, nullptr, &compiler)
== STATS_PREPROCESSING);
args_free(orig);
struct args *preprocessed, *compiler;
create_file("foo.c", "");
- CHECK(process_args(ctx, orig, &preprocessed, NULL, &compiler)
+ CHECK(process_args(ctx, orig, &preprocessed, nullptr, &compiler)
== STATS_UNSUPPORTED_OPTION);
args_free(orig);
struct args* orig =
args_init_from_string("cc " DEP_ARGS " -c foo.c -o foo.o");
struct args* exp_cpp = args_init_from_string("cc " DEP_ARGS);
- struct args* exp_extra = args_init(0, NULL);
+ struct args* exp_extra = args_init(0, nullptr);
struct args* exp_cc = args_init_from_string("cc -c");
#undef DEP_ARGS
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
ctx.config.set_run_second_cpp(false);
struct args* exp_extra = args_init_from_string(DEP_ARGS);
struct args* exp_cc = args_init_from_string("cc -c " DEP_ARGS);
#undef DEP_ARGS
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
CHECK(!process_args(ctx, orig, &act_cpp, &act_extra, &act_cc));
struct args* orig =
args_init_from_string("cc " CPP_ARGS " " DEP_ARGS " -c foo.c -o foo.o");
struct args* exp_cpp = args_init_from_string("cc " CPP_ARGS " " DEP_ARGS);
- struct args* exp_extra = args_init(0, NULL);
+ struct args* exp_extra = args_init(0, nullptr);
struct args* exp_cc = args_init_from_string("cc -c");
#undef DEP_ARGS
#undef CPP_ARGS
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
ctx.config.set_run_second_cpp(false);
struct args* exp_cc = args_init_from_string("cc " CPP_ARGS " -c " DEP_ARGS);
#undef DEP_ARGS
#undef CPP_ARGS
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
CHECK(!process_args(ctx, orig, &act_cpp, &act_extra, &act_cc));
struct args* exp_extra = args_init_from_string(DEP_ARGS);
struct args* exp_cc = args_init_from_string("cc -c " DEP_ARGS);
#undef DEP_ARGS
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
CHECK(!process_args(ctx, orig, &act_cpp, &act_extra, &act_cc));
struct args* exp_cpp = args_init_from_string("cc");
struct args* exp_extra = args_init_from_string("-MD -MF foo.d");
struct args* exp_cc = args_init_from_string("cc -c -MD -MF foo.d");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
CHECK(!process_args(ctx, orig, &act_cpp, &act_extra, &act_cc));
struct args* orig =
args_init_from_string("cc -c -MD foo.c -MF foo.d -o foo.o");
struct args* exp_cpp = args_init_from_string("cc -MD -MF foo.d -MQ foo.o");
- struct args* exp_extra = args_init(0, NULL);
+ struct args* exp_extra = args_init(0, nullptr);
struct args* exp_cc = args_init_from_string("cc -c");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
ctx.config.set_run_second_cpp(false);
struct args* orig = args_init_from_string("cc -c -MD foo.c -o foo.o");
struct args* exp_cpp = args_init_from_string("cc -MD -MF foo.d -MQ foo.o");
- struct args* exp_extra = args_init(0, NULL);
+ struct args* exp_extra = args_init(0, nullptr);
struct args* exp_cc = args_init_from_string("cc -c");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
struct args* exp_cpp = args_init_from_string("cc");
struct args* exp_extra = args_init_from_string("-MD");
struct args* exp_cc = args_init_from_string("cc -c -MD");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
struct args* exp_cpp = args_init_from_string("cc");
struct args* exp_extra = args_init_from_string("-MFpath");
struct args* exp_cc = args_init_from_string("cc -c -MFpath");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
char* arg_string;
struct args* orig;
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
ctx.config.set_base_dir(get_root());
char* arg_string;
struct args* orig;
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
ctx.config.set_base_dir(get_root());
struct args* exp_cpp = args_init_from_string("cc");
struct args* exp_extra = args_init_from_string("-MMD -MT bar -MFfoo.d");
struct args* exp_cc = args_init_from_string("cc -c -MMD -MT bar -MFfoo.d");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
args_init_from_string("-MMD -MFfoo.d -MT foo -MTbar");
struct args* exp_cc =
args_init_from_string("cc -c -MMD -MFfoo.d -MT foo -MTbar");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
args_init_from_string("-MMD -MFfoo.d -MQ foo -MQbar");
struct args* exp_cc =
args_init_from_string("cc -c -MMD -MFfoo.d -MQ foo -MQbar");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
struct args* exp_extra = args_init_from_string("-MD -MP -MFfoo.d -MQ foo.d");
struct args* exp_cc =
args_init_from_string("gcc -c -MD -MP -MFfoo.d -MQ foo.d");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
struct args* exp_extra = args_init_from_string("-MD -MP -MFfoo.d -MT foo.d");
struct args* exp_cc =
args_init_from_string("gcc -c -MD -MP -MFfoo.d -MT foo.d");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
struct args* exp_extra = args_init_from_string("-MD -MP -MFfoo.d -MQfoo.d");
struct args* exp_cc =
args_init_from_string("gcc -c -MD -MP -MFfoo.d -MQfoo.d");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
struct args* exp_extra = args_init_from_string("-MD -MP -MFfoo.d -MTfoo.d");
struct args* exp_cc =
args_init_from_string("gcc -c -MD -MP -MFfoo.d -MTfoo.d");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
struct args* orig =
args_init_from_string("gcc -c -fprofile-generate=some/dir foo.c");
struct args* exp_cpp = args_init_from_string("gcc");
- struct args* exp_extra = args_init(0, NULL);
+ struct args* exp_extra = args_init(0, nullptr);
struct args* exp_cc = args_init_from_string("gcc");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
char* s;
args_init_from_string("gcc -c -fprofile-generate=some/dir foo.c");
struct args* exp_cpp =
args_init_from_string("gcc -fprofile-generate=some/dir");
- struct args* exp_extra = args_init(0, NULL);
+ struct args* exp_extra = args_init(0, nullptr);
struct args* exp_cc =
args_init_from_string("gcc -fprofile-generate=some/dir -c");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
char* arg_string;
struct args* orig;
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
ctx.config.set_base_dir(get_root());
char* cwd;
char* arg_string;
struct args* orig;
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
ctx.config.set_base_dir("/"); // posix
char* cwd;
char* arg_string;
struct args* orig;
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
ctx.config.set_base_dir(x_strdup("/")); // posix
struct args* orig = args_init_from_string("cc -g1 -gsplit-dwarf foo.c -c");
struct args* exp_cpp = args_init_from_string("cc -g1 -gsplit-dwarf");
- struct args* exp_extra = args_init(0, NULL);
+ struct args* exp_extra = args_init(0, nullptr);
struct args* exp_cc = args_init_from_string("cc -g1 -gsplit-dwarf -c");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
CHECK(!process_args(ctx, orig, &act_cpp, &act_extra, &act_cc));
struct args* orig = args_init_from_string("cc -gsplit-dwarf -g1 foo.c -c");
struct args* exp_cpp = args_init_from_string("cc -gsplit-dwarf -g1");
- struct args* exp_extra = args_init(0, NULL);
+ struct args* exp_extra = args_init(0, nullptr);
struct args* exp_cc = args_init_from_string("cc -gsplit-dwarf -g1 -c");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
CHECK(!process_args(ctx, orig, &act_cpp, &act_extra, &act_cc));
" -Wa,foo -Werror -Xlinker fie -Xlinker,fum -Wno-error");
struct args* exp_cc = args_init_from_string(
"cc -g -Wa,foo -Werror -Xlinker fie -Xlinker,fum -Wno-error -DX -c");
- struct args* act_cpp = NULL;
- struct args* act_extra = NULL;
- struct args* act_cc = NULL;
+ struct args* act_cpp = nullptr;
+ struct args* act_extra = nullptr;
+ struct args* act_cc = nullptr;
create_file("foo.c", "");
CHECK(!process_args(ctx, orig, &act_cpp, &act_extra, &act_cc));
#include "../src/compopt.hpp"
#include "framework.hpp"
+bool compopt_verify_sortedness_and_flags();
+
TEST_SUITE(compopt)
TEST(option_table_should_be_sorted)
{
- bool compopt_verify_sortedness_and_flags(void);
CHECK(compopt_verify_sortedness_and_flags());
}
TEST(format_command)
{
- const char* argv[] = {"foo", "bar", NULL};
+ const char* argv[] = {"foo", "bar", nullptr};
CHECK_STR_EQ_FREE2("foo bar\n", format_command(argv));
}