Skip to content

Commit

Permalink
remove strnlen usage
Browse files Browse the repository at this point in the history
Under Cygwin, it needs _GNU_SOURCE, which is difficult to enable
manually. Usually needs -std=gnu++.
  • Loading branch information
neheb committed Jan 11, 2025
1 parent fb43251 commit af3e603
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on_PR_meson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:
pkgconf
- name: Compile and Test
run: |
meson setup build -Dwarning_level=3 -Dcpp_std=gnu++20
meson setup build -Dwarning_level=3
meson compile -C build --verbose
meson test -C build --verbose
MacOS:
Expand Down
2 changes: 1 addition & 1 deletion src/bmffimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
// Check that the string has a '\0' terminator.
const char* str = data.c_str(skip);
const size_t maxlen = data.size() - skip;
Internal::enforce(maxlen > 0 && strnlen(str, maxlen) < maxlen, Exiv2::ErrorCode::kerCorruptedMetadata);
Internal::enforce(maxlen > 0 && std::strlen(str) < maxlen, Exiv2::ErrorCode::kerCorruptedMetadata);
std::string name(str);
if (Internal::contains(name, "Exif")) { // "Exif" or "ExifExif"
exifID_ = ID;
Expand Down
5 changes: 4 additions & 1 deletion src/helper_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ std::string string_from_unterminated(const char* data, size_t data_length) {
if (data_length == 0) {
return {};
}
const size_t StringLength = strnlen(data, data_length);
size_t StringLength = 0;
while (StringLength < data_length && data[StringLength] != '\0') {
StringLength++;
}
return {data, StringLength};
}

Expand Down

0 comments on commit af3e603

Please sign in to comment.