Skip to content

Commit

Permalink
tools/ls: fix compile with -O2
Browse files Browse the repository at this point in the history
  • Loading branch information
Gottox committed May 30, 2023
1 parent 65e47df commit ca98392
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tools/ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,20 @@ static int
ls_item(struct SqshArchive *archive, const char *path,
struct SqshDirectoryIterator *iter) {
int rv = 0;
int len = 0;
struct SqshInode *entry_inode = NULL;
const char *name = sqsh_directory_iterator_name(iter);
const int name_size = sqsh_directory_iterator_name_size(iter);
size_t current_path_size = name_size + strlen(path ? path : "") + 2;
const size_t path_len = path ? strlen(path) : 0;
const size_t current_path_size = name_size + path_len + 2;
char *current_path = calloc(current_path_size, sizeof(char));

if (current_path == NULL) {
rv = -SQSH_ERROR_MALLOC_FAILED;
goto out;
}
if (path != NULL) {
len = strlen(path);
strncpy(current_path, path, current_path_size - 1);
if (len > 0 && path[len - 1] != '/') {
memcpy(current_path, path, path_len);
if (path_len > 0 && path[path_len - 1] != '/') {
strncat(current_path, "/", 2);
}
}
Expand Down

0 comments on commit ca98392

Please sign in to comment.