Skip to content

Commit

Permalink
Merge pull request #194 from Gottox/improve/use-memchr-instead-of-for…
Browse files Browse the repository at this point in the history
…-loop

directory_iterator: use memchr for consistency checking
  • Loading branch information
Gottox authored Dec 14, 2023
2 parents bec925a + ca8cc21 commit 9372c5b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions libsqsh/src/directory/directory_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,11 @@ check_entry_name_consistency(const struct SqshDirectoryIterator *iterator) {
size_t name_len;
const char *name = sqsh_directory_iterator_name2(iterator, &name_len);

for (size_t i = 0; i < name_len; i++) {
if (name[i] == '\0' || name[i] == '/') {
return -SQSH_ERROR_CORRUPTED_DIRECTORY_ENTRY;
}
if (memchr(name, '\0', name_len) != NULL) {
return -SQSH_ERROR_CORRUPTED_DIRECTORY_ENTRY;
} else if (memchr(name, '/', name_len) != NULL) {
return -SQSH_ERROR_CORRUPTED_DIRECTORY_ENTRY;
}

return 0;
}

Expand Down

0 comments on commit 9372c5b

Please sign in to comment.