Skip to content

Commit 1f7af9c

Browse files
committed
Fix format warning for st_size base type linux vs mac
Also check buffer size
1 parent fdfd22c commit 1f7af9c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/openvfsfuse.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,12 @@ static int openVFSfuse_getxattr(const char *orig_path, const char *name, char *v
702702
if (lstat(path.c_str(), &statbuf) == -1) {
703703
return -errno;
704704
}
705-
return std::snprintf(value, size, "%lld", statbuf.st_size);
705+
const auto realSize = std::to_string(statbuf.st_size);
706+
if (realSize.size() < size) {
707+
std::ranges::copy(realSize, value);
708+
return static_cast<int>(realSize.size());
709+
}
710+
return -ERANGE;
706711
}
707712
const auto ret = Xattr::getxattr(path, name, value, size);
708713
if (ret == -ENODATA && name == OpenVfsConstants::XAttributeNames::Data) {
@@ -711,7 +716,7 @@ static int openVFSfuse_getxattr(const char *orig_path, const char *name, char *v
711716
static const auto defaultData = OpenVfsAttributes::PlaceHolderAttributes({}).toData();
712717
if (size > defaultData.size()) {
713718
errno = 0;
714-
std::copy(defaultData.begin(), defaultData.end(), value);
719+
std::ranges::copy(defaultData, value);
715720
openvfsfuse_log(path, "getxattr", 0, "Returning default data for %s: %s", name, value);
716721
return static_cast<int>(defaultData.size());
717722
}

0 commit comments

Comments
 (0)