From c215d7911baf0c17181dda3f2d613bedab11cb88 Mon Sep 17 00:00:00 2001 From: jikai Date: Tue, 14 May 2024 07:50:38 +0000 Subject: [PATCH 14/14] add codecheck fix Signed-off-by: jikai --- src/runtime/conf.c | 2 +- src/runtime/conf.h | 2 +- src/runtime/error.c | 1 - src/utils/utils_array.h | 6 +++--- src/utils/utils_cgroup.c | 2 +- src/utils/utils_cgroup.h | 5 +++-- src/utils/utils_convert.c | 2 +- src/utils/utils_convert.h | 2 +- src/utils/utils_file.c | 16 ++++++++-------- src/utils/utils_mainloop.c | 2 +- src/utils/utils_memory.h | 1 - src/utils/utils_string.h | 2 +- 12 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/runtime/conf.c b/src/runtime/conf.c index de07353..5cf6e3f 100644 --- a/src/runtime/conf.c +++ b/src/runtime/conf.c @@ -3242,7 +3242,7 @@ static int add_needed_net_conf(struct isula_linked_list *conf) } /* get needed lxc conf */ -struct isula_linked_list *get_needed_lxc_conf() +struct isula_linked_list *get_needed_lxc_conf(void) { struct isula_linked_list *conf = isula_common_calloc_s(sizeof(*conf)); if (conf == NULL) { diff --git a/src/runtime/conf.h b/src/runtime/conf.h index 7ee8184..45cee0a 100644 --- a/src/runtime/conf.h +++ b/src/runtime/conf.h @@ -117,7 +117,7 @@ struct isula_linked_list *trans_annotations(const json_map_string_string *anno); /* * Get other lxc needed configurations */ -struct isula_linked_list *get_needed_lxc_conf(); +struct isula_linked_list *get_needed_lxc_conf(void); bool is_system_container(const oci_runtime_spec *container); diff --git a/src/runtime/error.c b/src/runtime/error.c index d0bfcce..52561b1 100644 --- a/src/runtime/error.c +++ b/src/runtime/error.c @@ -27,7 +27,6 @@ #include "utils_memory.h" #include "utils_string.h" -#include "constants.h" // record the lcr error __thread engine_error_t g_lcr_error = { diff --git a/src/utils/utils_array.h b/src/utils/utils_array.h index 1fc167d..527b0f4 100644 --- a/src/utils/utils_array.h +++ b/src/utils/utils_array.h @@ -29,11 +29,11 @@ extern "C" { #endif -void isula_free_array(void **array); +void isula_free_array(void **orig_array); -int isula_grow_array(void ***array, size_t *capacity, size_t new_size, size_t capacity_increment); +int isula_grow_array(void ***orig_array, size_t *orig_capacity, size_t size, size_t increment); -size_t isula_array_len(void **array); +size_t isula_array_len(void **orig_array); typedef void *(*clone_cb)(const void *src); int isula_array_append(void ***array, const void *element, clone_cb cb); diff --git a/src/utils/utils_cgroup.c b/src/utils/utils_cgroup.c index bd3bc42..71fcc1b 100644 --- a/src/utils/utils_cgroup.c +++ b/src/utils/utils_cgroup.c @@ -81,7 +81,7 @@ uint64_t lcr_util_trans_blkio_weight_to_io_bfq_weight(int weight) return (uint64_t)(1 + ((uint64_t)weight - 10) * 999 / 990); } -int lcr_util_get_cgroup_version() +int lcr_util_get_cgroup_version(void) { struct statfs fs = {0}; diff --git a/src/utils/utils_cgroup.h b/src/utils/utils_cgroup.h index 18b404b..e82adfb 100644 --- a/src/utils/utils_cgroup.h +++ b/src/utils/utils_cgroup.h @@ -23,9 +23,10 @@ #ifndef _ISULA_UTILS_UTILS_CGROUP_H #define _ISULA_UTILS_UTILS_CGROUP_H +#include + #include #include -#include #ifdef __cplusplus extern "C" { @@ -54,7 +55,7 @@ int lcr_util_get_real_swap(int64_t memory, int64_t memory_swap, int64_t *swap); int lcr_util_trans_cpushare_to_cpuweight(int64_t cpu_share); uint64_t lcr_util_trans_blkio_weight_to_io_weight(int weight); uint64_t lcr_util_trans_blkio_weight_to_io_bfq_weight(int weight); -int lcr_util_get_cgroup_version(); +int lcr_util_get_cgroup_version(void); #ifdef __cplusplus } diff --git a/src/utils/utils_convert.c b/src/utils/utils_convert.c index f3e38c4..6bdeb04 100644 --- a/src/utils/utils_convert.c +++ b/src/utils/utils_convert.c @@ -325,7 +325,7 @@ int isula_parse_byte_size_string(const char *s, int64_t *converted) } ret = parse_unit_multiple(pmlt, &mltpl); - if (ret) { + if (ret != 0) { return ret; } diff --git a/src/utils/utils_convert.h b/src/utils/utils_convert.h index 47d37e7..ac34772 100644 --- a/src/utils/utils_convert.h +++ b/src/utils/utils_convert.h @@ -43,7 +43,7 @@ int isula_safe_strto_uint16(const char *numstr, uint16_t *converted); int isula_safe_strto_uint64(const char *numstr, uint64_t *converted); -int isula_safe_strto_int(const char *numstr, int *converted); +int isula_safe_strto_int(const char *num_str, int *converted); int isula_safe_strto_uint(const char *numstr, unsigned int *converted); diff --git a/src/utils/utils_file.c b/src/utils/utils_file.c index d7ff4af..b742d20 100644 --- a/src/utils/utils_file.c +++ b/src/utils/utils_file.c @@ -62,12 +62,12 @@ static int do_clean_path(const char *respath, const char *limit_respath, const c char *dest = *dst; const char *endpos = stpos; - for (; *stpos; stpos = endpos) { + for (; *stpos != '\0'; stpos = endpos) { while (ISSLASH(*stpos)) { ++stpos; } - for (endpos = stpos; *endpos && !ISSLASH(*endpos); ++endpos) { + for (endpos = stpos; (*endpos != '\0') && !ISSLASH(*endpos); ++endpos) { } if (endpos - stpos == 0) { @@ -139,7 +139,7 @@ char *isula_clean_path(const char *path, char *realpath, size_t realpath_len) stpos = path; } - if (do_clean_path(respath, limit_respath, stpos, &dest)) { + if (do_clean_path(respath, limit_respath, stpos, &dest) != 0) { return NULL; } @@ -243,7 +243,7 @@ static void util_rmdir_one(const char *dirpath, const struct dirent *pdirent, in } nret = lstat(fname, &fstat); - if (nret) { + if (nret != 0) { ERROR("Failed to stat %s", fname); *failure = -1; return; @@ -405,9 +405,9 @@ int isula_dir_build(const char *name) continue; } set_char_to_terminator(p); - if (access(n, F_OK)) { + if (access(n, F_OK) != 0) { nret = mkdir(n, DEFAULT_SECURE_DIRECTORY_MODE); - if (nret && (errno != EEXIST || !isula_dir_exists(n))) { + if (nret != 0 && (errno != EEXIST || !isula_dir_exists(n))) { ERROR("failed to create directory '%s'.", n); free(n); return -1; @@ -451,7 +451,7 @@ int isula_dir_recursive_mk(const char *dir, mode_t mode) ERROR("strndup failed"); return -1; } - if (*cur_dir) { + if (*cur_dir != '\0') { ret = mkdir(cur_dir, mode); if (ret != 0 && (errno != EEXIST || !isula_dir_exists(cur_dir))) { SYSERROR("failed to create directory '%s'", cur_dir); @@ -536,7 +536,7 @@ static int append_new_content_to_file(FILE *fp, const char *content) return -1; } util_trim_newline(line); - if (!strcmp(content, line)) { + if (strcmp(content, line) == 0) { need_append = false; break; } diff --git a/src/utils/utils_mainloop.c b/src/utils/utils_mainloop.c index cc6a8ae..c45b32c 100644 --- a/src/utils/utils_mainloop.c +++ b/src/utils/utils_mainloop.c @@ -142,7 +142,7 @@ int isula_epoll_remove_handler(isula_epoll_descr_t *descr, int fd) epoll_handler = index->elem; if (fd == epoll_handler->cbfd) { - if (epoll_ctl(descr->fd, EPOLL_CTL_DEL, fd, NULL)) { + if (epoll_ctl(descr->fd, EPOLL_CTL_DEL, fd, NULL) != 0) { return -1; } diff --git a/src/utils/utils_memory.h b/src/utils/utils_memory.h index 4749622..7b9528c 100644 --- a/src/utils/utils_memory.h +++ b/src/utils/utils_memory.h @@ -23,7 +23,6 @@ #ifndef _ISULA_UTILS_UTILS_MEMORY_H #define _ISULA_UTILS_UTILS_MEMORY_H -#include #include #include diff --git a/src/utils/utils_string.h b/src/utils/utils_string.h index 5a25531..407158c 100644 --- a/src/utils/utils_string.h +++ b/src/utils/utils_string.h @@ -48,7 +48,7 @@ char *isula_string_append(const char *pre, const char *add_str); /* * Replace 'needle' in string haystack with 'replacement'; */ -char *isula_string_replace(const char *needle, const char *replacement, const char *haystack); +char *isula_string_replace(const char *needle, const char *replace, const char *haystack); struct __isula_string_array; -- 2.34.1