-
Notifications
You must be signed in to change notification settings - Fork 15
Closed
Description
Description
When you try to load a file that doesn't exist (using std::ifstream
), InputType
will be null and from what I saw, this isn't checked anywhere. I suppose this should be checked inside input_adapter
function:
fkYAML/include/fkYAML/detail/input/input_adapter.hpp
Lines 926 to 932 in 93b0e43
/// @brief A factory method for stream_input_adapter objects with std::istream objects. | |
/// @param stream An input stream. | |
/// @return stream_input_adapter A stream_input_adapter object. | |
inline stream_input_adapter input_adapter(std::istream& stream) noexcept { | |
utf_encode_t encode_type = detect_encoding_and_skip_bom(stream); | |
return stream_input_adapter(stream, encode_type); | |
} |
this issue doesn't occur when std::FILE*
is used, because:
fkYAML/include/fkYAML/detail/input/input_adapter.hpp
Lines 915 to 924 in 93b0e43
/// @brief A factory method for file_input_adapter objects with C-style file handles. | |
/// @param file A file handle. | |
/// @return file_input_adapter A file_input_adapter object. | |
inline file_input_adapter input_adapter(std::FILE* file) { | |
if (!file) { | |
throw fkyaml::exception("Invalid FILE object pointer."); | |
} | |
utf_encode_t encode_type = detect_encoding_and_skip_bom(file); | |
return file_input_adapter(file, encode_type); | |
} |
we have condition to check file pointer inside input_adapter
for std::FILE*
Reproduction steps
- Use code from tutorial (https://fktn-k.github.io/fkYAML/tutorials/#__tabbed_1_2)
- Make sure file doesn't exist
- Compile and test = infinity loop because stream is empty
Expected vs. actual results
Expected result is throw fkyaml::exception, currently we have infinity loop
Minimal code example
No response
Error messages
No response
Compiler and operating system
Windows: C++latest, MSVC latest
Library version
0.3.9/0.3.10
Validation
- The bug also occurs if the latest version from the
develop
branch is used. - I can successfully compile and run the unit tests.
fktn-k
Metadata
Metadata
Assignees
Labels
No labels