Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang tidy cleanup #276

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/check_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,24 @@ int found_issue = 0;
int suppress_output = 0;
int full_path = 0;

#define ALLOC_NODE(nl) if (ck->check_nodes[nl]) { \
loc = ck->check_nodes[nl]; \
while (loc->next) { loc = loc->next; } \
loc->next = xmalloc(sizeof(struct check_node)); \
if (!loc->next) { return SELINT_OUT_OF_MEM; } \
loc = loc->next; \
} else { \
ck->check_nodes[nl] = xmalloc(sizeof(struct check_node)); \
if (!ck->check_nodes[nl]) { return SELINT_OUT_OF_MEM; } \
loc = ck->check_nodes[nl]; \
}

enum selint_error add_check(enum node_flavor check_flavor, struct checks *ck,
const char *check_id,
struct check_result *(*check_function)(const struct check_data *check_data,
const struct policy_node *node))
{
struct check_node *loc;

ALLOC_NODE(check_flavor);
if (ck->check_nodes[check_flavor]) {
loc = ck->check_nodes[check_flavor];
while (loc->next) {
loc = loc->next;
}
loc->next = xmalloc(sizeof(struct check_node));
loc = loc->next;
} else {
ck->check_nodes[check_flavor] = xmalloc(sizeof(struct check_node));
loc = ck->check_nodes[check_flavor];
}

loc->check_function = check_function;
loc->check_id = xstrdup(check_id);
Expand Down
1 change: 1 addition & 0 deletions src/ordering.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ const char *get_section(const struct policy_node *node)
case NODE_SPT_FILE:
case NODE_AV_FILE:
case NODE_COND_FILE:
case NODE_CLEANUP:
return NULL; // Should never happen
case NODE_HEADER:
return SECTION_NON_ORDERED; // Guaranteed at top by grammar
Expand Down
2 changes: 1 addition & 1 deletion src/parse_fc.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ bool check_for_fc_macro(const char *line, const struct string_list *custom_fc_ma

struct policy_node *parse_fc_file(const char *filename, const struct string_list *custom_fc_macros)
{
FILE *fd = fopen(filename, "r");
FILE *fd = fopen(filename, "re");

if (!fd) {
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct policy_node *parse_one_file(const char *filename, enum node_flavor flavor
set_current_module_name(mod_name);
free(copy);

FILE *f = fopen(filename, "r");
FILE *f = fopen(filename, "re");
if (!f) {
printf("%sError%s: Failed to open %s: %s\n", color_error(), color_reset(), filename, strerror(errno));
return NULL;
Expand Down
8 changes: 4 additions & 4 deletions src/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ enum selint_error load_access_vectors_source(const char *av_path)

set_current_module_name(av_path);

FILE *f = fopen(av_path, "r");
FILE *f = fopen(av_path, "re");
if (!f) {
printf("%sError%s: Failed to open %s: %s\n", color_error(), color_reset(), av_path, strerror(errno));
return SELINT_IO_ERROR;
Expand Down Expand Up @@ -193,7 +193,7 @@ static char *strip_space(char *str)

enum selint_error load_modules_source(const char *modules_conf_path)
{
FILE *fd = fopen(modules_conf_path, "r");
FILE *fd = fopen(modules_conf_path, "re");

if (!fd) {
return SELINT_IO_ERROR;
Expand Down Expand Up @@ -242,7 +242,7 @@ enum selint_error load_modules_source(const char *modules_conf_path)

enum selint_error load_obj_perm_sets_source(const char *obj_perm_sets_path)
{
FILE *f = fopen(obj_perm_sets_path, "r");
FILE *f = fopen(obj_perm_sets_path, "re");
if (!f) {
return SELINT_IO_ERROR;
}
Expand Down Expand Up @@ -321,7 +321,7 @@ static enum selint_error load_global_conditions_file(const char *path)

set_current_module_name("__global__");

FILE *f = fopen(path, "r");
FILE *f = fopen(path, "re");
if (!f) {
printf("%sError%s: Failed to open file %s: %s\n", color_error(), color_reset(), path, strerror(errno));
return SELINT_IO_ERROR;
Expand Down
2 changes: 2 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#define UTIL_H

#include <stdbool.h>
#include <stddef.h>
#include <string.h>

// ignore conversions discarding const specifier, e.g.
// const char [] -> char *
Expand Down