aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-dataloader/File.hpp
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2024-08-03 23:29:33 +0200
committer Spartan322 <Megacake1234@gmail.com>2024-08-03 23:29:33 +0200
commit2addc7763556ff76809f14e2063d1452aa9d6275 (patch)
tree996cac9cfa3c18798b5e509f51935a2538baac3f /src/openvic-dataloader/File.hpp
parent2f6f6bdbb191aca01a1c4a9587e314442d219fb4 (diff)
Fix crash for empty/invalid/not-found filepaths
Add tests to validate empty string path Add tests to validate non-existent string path Add tests to validate nullptr buffer parser
Diffstat (limited to 'src/openvic-dataloader/File.hpp')
-rw-r--r--src/openvic-dataloader/File.hpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/openvic-dataloader/File.hpp b/src/openvic-dataloader/File.hpp
index ec25640..cdab377 100644
--- a/src/openvic-dataloader/File.hpp
+++ b/src/openvic-dataloader/File.hpp
@@ -23,6 +23,7 @@ namespace ovdl {
lexy::buffer<lexy::utf32_encoding, void>,
lexy::buffer<lexy::byte_encoding, void>>;
+ File() = default;
explicit File(const char* path);
const char* path() const noexcept;
@@ -74,6 +75,7 @@ namespace ovdl {
decltype(auto) visit_buffer(Visitor&& visitor) {
switch (_buffer.index()) {
SWITCH_LIST
+ case 0: return visitor(lexy::buffer<> {});
default: ovdl::detail::unreachable();
}
}
@@ -82,6 +84,7 @@ namespace ovdl {
Return visit_buffer(Visitor&& visitor) {
switch (_buffer.index()) {
SWITCH_LIST
+ case 0: return visitor(lexy::buffer<> {});
default: ovdl::detail::unreachable();
}
}
@@ -90,6 +93,7 @@ namespace ovdl {
decltype(auto) visit_buffer(Visitor&& visitor) const {
switch (_buffer.index()) {
SWITCH_LIST
+ case 0: return visitor(lexy::buffer<> {});
default: ovdl::detail::unreachable();
}
}
@@ -98,6 +102,7 @@ namespace ovdl {
Return visit_buffer(Visitor&& visitor) const {
switch (_buffer.index()) {
SWITCH_LIST
+ case 0: return visitor(lexy::buffer<> {});
default: ovdl::detail::unreachable();
}
}
@@ -105,7 +110,7 @@ namespace ovdl {
#undef SWITCH_LIST
protected:
- const char* _path;
+ const char* _path = "";
std::size_t _buffer_size = 0;
detail::type_prepend_t<buffer_ids::variant_type, std::monostate> _buffer;
};
@@ -114,6 +119,8 @@ namespace ovdl {
struct BasicFile : File {
using node_type = NodeT;
+ BasicFile() = default;
+
template<typename Encoding, typename MemoryResource = void>
explicit BasicFile(const char* path, lexy::buffer<Encoding, MemoryResource>&& buffer)
: File(path) {