Skip to content

Commit

Permalink
Fixed C++ compiler warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
  • Loading branch information
larsewi committed Jan 16, 2025
1 parent 3ee4317 commit d8c5e33
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
13 changes: 10 additions & 3 deletions lib/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,23 @@ char *LCH_BlockIdFromArgument(const char *const work_dir,
LCH_List *const blocks = LCH_FileListDirectory(path, true);

/* Add genesis block to the list */
if (!LCH_ListAppend(blocks, LCH_GENISIS_BLOCK_ID, NULL)) {
char *const genisis_id = LCH_StringDuplicate(LCH_GENISIS_BLOCK_ID);
if (genisis_id == NULL) {
LCH_ListDestroy(blocks);
return NULL;
}

if (!LCH_ListAppend(blocks, genisis_id, free)) {
/* Error already logged */
free(genisis_id);
LCH_ListDestroy(blocks);
return NULL;
}

const size_t num_blocks = LCH_ListLength(blocks);

for (size_t i = 0; i < num_blocks; i++) {
const char *const filename = LCH_ListGet(blocks, i);
const char *const filename = (char *)LCH_ListGet(blocks, i);
if (!IsValidBlockId(filename)) {
LCH_LOG_WARNING(
"The file '%s%c%s' does not conform with the block naming convention "
Expand All @@ -263,7 +270,7 @@ char *LCH_BlockIdFromArgument(const char *const work_dir,
(num_matching > 1) ? "Ambiguous" : "Unknown", argument,
num_matching);
} else {
const char *const filename = LCH_ListGet(blocks, index);
const char *const filename = (char *)LCH_ListGet(blocks, index);
block_id = LCH_StringDuplicate(filename);
}

Expand Down
8 changes: 5 additions & 3 deletions lib/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ bool LCH_FileExists(const char *const path) {
/******************************************************************************/

bool LCH_FileIsRegular(const char *const path) {
struct stat sb = {0};
struct stat sb;
memset(&sb, 0, sizeof(struct stat));
const bool is_regular =
(lstat(path, &sb) == 0) && ((sb.st_mode & S_IFMT) == S_IFREG);
return is_regular;
Expand All @@ -60,7 +61,8 @@ bool LCH_FileIsRegular(const char *const path) {
/******************************************************************************/

bool LCH_FileIsDirectory(const char *const path) {
struct stat sb = {0};
struct stat sb;
memset(&sb, 0, sizeof(struct stat));
const bool is_directory =
(lstat(path, &sb) == 0) && ((sb.st_mode & S_IFMT) == S_IFDIR);
return is_directory;
Expand Down Expand Up @@ -122,7 +124,7 @@ bool LCH_FileDelete(const char *const parent) {
const size_t num_children = LCH_ListLength(children);

for (size_t i = 0; i < num_children; i++) {
const char *const child = LCH_ListGet(children, i);
const char *const child = (char *)LCH_ListGet(children, i);
assert(child != NULL);

if (LCH_StringEqual(child, ".") || LCH_StringEqual(child, "..")) {
Expand Down
4 changes: 2 additions & 2 deletions tests/check_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ START_TEST(test_LCH_BlockCreate) {
END_TEST

START_TEST(test_LCH_BlockIdFromArgument) {
char template[] = "tmp_XXXXXX";
const char *work_dir = mkdtemp(template);
char tmpl[] = "tmp_XXXXXX";
const char *work_dir = mkdtemp(tmpl);
ck_assert_ptr_nonnull(work_dir);

const char *blocks[] = {
Expand Down

0 comments on commit d8c5e33

Please sign in to comment.