Skip to content

Commit 70d20a3

Browse files
Fixed CHECK_RETURN Coverity issues
lib/pkg_editor/src/pkg_editor.c:1604:3: Type: Unchecked return value from library (CHECKED_RETURN) lib/pkg_editor/src/pkg_editor.c:1584:3: Unchecked call to function 1. path: Condition "buffer != NULL", taking true branch. lib/pkg_editor/src/pkg_editor.c:1585:5: 2. path: Condition "input == NULL", taking true branch. lib/pkg_editor/src/pkg_editor.c:1585:5: 3. path: Falling through to end of if statement. lib/pkg_editor/src/pkg_editor.c:1588:3: 4. path: Falling through to end of if statement. lib/pkg_editor/src/pkg_editor.c:1594:3: 5. path: Condition "ret != 0", taking false branch. lib/pkg_editor/src/pkg_editor.c:1604:3: 6. check_return: Calling "mkdir(full_name, 493U)" without checking return value. This library function may fail and return an error code. lib/pkg_editor/src/pkg_editor.c:1651:7: Type: Unchecked return value from library (CHECKED_RETURN) lib/pkg_editor/src/pkg_editor.c:1584:3: Unchecked call to function 1. path: Condition "buffer != NULL", taking true branch. lib/pkg_editor/src/pkg_editor.c:1585:5: 2. path: Condition "input == NULL", taking true branch. lib/pkg_editor/src/pkg_editor.c:1585:5: 3. path: Falling through to end of if statement. lib/pkg_editor/src/pkg_editor.c:1588:3: 4. path: Falling through to end of if statement. lib/pkg_editor/src/pkg_editor.c:1594:3: 5. path: Condition "ret != 0", taking false branch. lib/pkg_editor/src/pkg_editor.c:1610:3: 6. path: Condition "z_info.strm.avail_in > 0", taking true branch. lib/pkg_editor/src/pkg_editor.c:1612:5: 7. path: Condition "!read_data(&info, 20UL /* sizeof (info) */, &z_info, input)", taking false branch. lib/pkg_editor/src/pkg_editor.c:1617:5: 8. path: Condition "info.magic != 3203399403U", taking false branch. lib/pkg_editor/src/pkg_editor.c:1625:5: 9. path: Condition "info.kind == PACK_END", taking false branch. lib/pkg_editor/src/pkg_editor.c:1630:5: 10. path: Condition "!read_data(name, info.name_length, &z_info, input)", taking false branch. lib/pkg_editor/src/pkg_editor.c:1638:5: 11. path: Condition "12288UL /* 3 * 4096 */ < out_dir_length", taking true branch. lib/pkg_editor/src/pkg_editor.c:1643:5: 12. path: Condition "full_name[12287 /* 3 * 4096 - 1 */] != 0", taking true branch. lib/pkg_editor/src/pkg_editor.c:1647:5: 13. path: Condition "info.kind == PACK_DIR", taking true branch. lib/pkg_editor/src/pkg_editor.c:1651:7: 14. check_return: Calling "mkdir(full_name, 493U)" without checking return value. This library function may fail and return an error code.
1 parent 56ab605 commit 70d20a3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/pkg_editor/src/pkg_editor.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,17 @@ int acl_pkg_pack(const char *out_file, const char **input_files_dirs) {
15111511
return 1 /* success */;
15121512
}
15131513

1514+
static void create_dir(const char *dir_name) {
1515+
// Create output directory. We can ignore the error output since it will
1516+
// only delay the failure to the first attempt of creating a file in the
1517+
// (not) newly created directory.
1518+
#ifdef _WIN32
1519+
(void)CreateDirectory(dir_name, NULL);
1520+
#else
1521+
(void)mkdir(dir_name, 0755);
1522+
#endif
1523+
}
1524+
15141525
static int read_data(void *data, size_t size, ZInfo *z_info, FILE *in_fd) {
15151526
// We want to fill 'data' with 'size' bytes.
15161527
z_info->strm.next_out = data;
@@ -1596,12 +1607,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
15961607
return 0;
15971608
}
15981609

1599-
// Create output directory (ignore any errors).
1600-
#ifdef _WIN32
1601-
CreateDirectory(full_name, NULL);
1602-
#else
1603-
mkdir(full_name, 0755);
1604-
#endif
1610+
create_dir(full_name);
16051611
full_name[out_dir_length] = '/';
16061612

16071613
// Process the file until we hit the PACK_END record (or finish the
@@ -1647,11 +1653,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
16471653
full_name[FULL_NAME_LEN - 1] = '\0';
16481654

16491655
if (info.kind == PACK_DIR) {
1650-
#ifdef _WIN32
1651-
CreateDirectory(full_name, NULL);
1652-
#else
1653-
mkdir(full_name, 0755);
1654-
#endif
1656+
create_dir(full_name);
16551657
} else {
16561658
// Read file contents
16571659
FILE *out_file = fopen(full_name, "wb");

0 commit comments

Comments
 (0)