Skip to content

Commit

Permalink
libsemanage: adjust sizes to avoid implicit truncations
Browse files Browse the repository at this point in the history
Use size_t for sizes and align miscellaneous type mismatches.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
  • Loading branch information
cgzones authored and jwcart2 committed Nov 21, 2024
1 parent cb54b1d commit d57fbb1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion libsemanage/src/compressed_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static ssize_t bunzip(semanage_handle_t *sh, FILE *f, void **data)
size_t total = 0;
uint8_t* uncompress = NULL;
uint8_t* tmpalloc = NULL;
int ret = -1;
ssize_t ret = -1;

buf = malloc(bufsize);
if (buf == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion libsemanage/src/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ int semanage_get_hll_compiler_path(semanage_handle_t *sh,
}

num_printed = snprintf(compiler, len, "%s/%s", sh->conf->compiler_directory_path, lower_lang_ext);
if (num_printed < 0 || (int)num_printed >= (int)len) {
if (num_printed < 0 || (size_t)num_printed >= len) {
ERR(sh, "Error creating compiler path.");
status = -1;
goto cleanup;
Expand Down
4 changes: 2 additions & 2 deletions libsemanage/src/parse_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int parse_skip_space(semanage_handle_t * handle, parse_info_t * info)

size_t buf_len = 0;
ssize_t len;
int lineno = info->lineno;
unsigned int lineno = info->lineno;
char *buffer = NULL;
char *ptr;

Expand Down Expand Up @@ -271,7 +271,7 @@ int parse_fetch_string(semanage_handle_t * handle,
{

const char *start = info->ptr;
int len = 0;
size_t len = 0;
char *tmp_str = NULL;

if (parse_assert_noeof(handle, info) < 0)
Expand Down
12 changes: 6 additions & 6 deletions libsemanage/src/semanage_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ typedef struct semanage_file_context_node {
char *path;
char *file_type;
char *context;
int path_len;
int effective_len;
int type_len;
int context_len;
size_t path_len;
size_t effective_len;
size_t type_len;
size_t context_len;
int meta; /* position of first meta char in path, -1 if none */
struct semanage_file_context_node *next;
} semanage_file_context_node_t;
Expand Down Expand Up @@ -514,7 +514,7 @@ const char *semanage_final_path(enum semanage_final_defs store,
char *semanage_conf_path(void)
{
char *semanage_conf = NULL;
int len;
size_t len;
struct stat sb;

len = strlen(semanage_root()) + strlen(selinux_path()) + strlen(SEMANAGE_CONF_FILE);
Expand Down Expand Up @@ -2893,7 +2893,7 @@ int semanage_nc_sort(semanage_handle_t * sh, const char *buf, size_t buf_len,

/* parsing bits */
const char *priority_names[] = NC_SORT_NAMES;
const int priority_names_len[] = NC_SORT_NAMES_LEN;
const size_t priority_names_len[] = NC_SORT_NAMES_LEN;
size_t line_len, buf_remainder, i, offset;
const char *line_buf, *line_end;

Expand Down
6 changes: 3 additions & 3 deletions libsemanage/src/utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ int semanage_cmp_plist_t(const void *x, const void *y)
return strcmp((*l1)->data, (*l2)->data);
}

int semanage_str_count(const char *data, char what)
size_t semanage_str_count(const char *data, char what)
{
int count = 0;
size_t count = 0;

if (!data)
return 0;
Expand All @@ -219,7 +219,7 @@ int semanage_str_count(const char *data, char what)

void semanage_rtrim(char *str, char trim_to)
{
int len = 0;
size_t len;

if (!str)
return;
Expand Down
2 changes: 1 addition & 1 deletion libsemanage/src/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int semanage_cmp_plist_t(const void *x, const void *y);
* @param what a character
* @returns the number of times the char appears in the string
*/
int semanage_str_count(const char *data, char what);
size_t semanage_str_count(const char *data, char what);
/**
* @param - a string
* @param the character to trim to
Expand Down

0 comments on commit d57fbb1

Please sign in to comment.