File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 1212#include " daw_attributes.h"
1313#include " daw_traits.h"
1414
15+ #include < cstddef>
1516#include < cstdio>
1617#include < exception>
1718#include < filesystem>
@@ -28,7 +29,13 @@ namespace daw {
2829 if ( fsize == 0 ) {
2930 return std::basic_string<CharT>{ };
3031 }
31- auto result = std::basic_string<CharT>( fsize, CharT{ } );
32+ if ( static_cast <std::uintmax_t >( std::basic_string<CharT>{ }.max_size ( ) ) <
33+ fsize ) {
34+ // File is too big to fit into string(WIN32)
35+ return std::nullopt ;
36+ }
37+ auto result =
38+ std::basic_string<CharT>( static_cast <std::size_t >( fsize ), CharT{ } );
3239 auto *f = fopen ( path.c_str ( ), " rb" );
3340 if ( not f ) {
3441 return std::nullopt ;
@@ -62,7 +69,13 @@ namespace daw {
6269 if ( fsize == 0 ) {
6370 return std::basic_string<CharT>{ };
6471 }
65- auto result = std::basic_string<CharT>( fsize, CharT{ } );
72+ if ( static_cast <std::uintmax_t >( std::basic_string<CharT>{ }.max_size ( ) ) <
73+ fsize ) {
74+ // File is too big to fit into string(WIN32)
75+ return std::nullopt ;
76+ }
77+ auto result =
78+ std::basic_string<CharT>( static_cast <std::size_t >( fsize ), CharT{ } );
6679 auto *f = _wfopen ( path.c_str ( ), L" rb" );
6780 if ( not f ) {
6881 return std::nullopt ;
You can’t perform that action at this time.
0 commit comments