5050#include < unicode/unistr.h>
5151
5252/* modern.cpp.core */
53+ #include < Logger.h>
5354#include < StringUtils.h>
5455
5556/* local header */
@@ -69,6 +70,9 @@ namespace vx::sqlite_utils {
6970
7071 constexpr double earthBlubKm = 6378.137 ;
7172
73+ /* * @brief Buffer size for errno. */
74+ constexpr std::int32_t errnoBufferSize = 128 ;
75+
7276 void sqlite3_deleter::operator ()( sqlite3 *_handle ) const noexcept {
7377
7478 [[maybe_unused]] const std::int32_t resultCode = sqlite3_close ( _handle );
@@ -375,7 +379,25 @@ namespace vx::sqlite_utils {
375379
376380 auto *databuffer ( static_cast <char *>( sqlite3_malloc64 ( sizeof ( char ) * str.size () ) ) );
377381#ifdef _WIN32
378- std::strncpy_s ( databuffer, str.size (), str.data (), str.size () );
382+ errno_t error = std::strncpy_s ( databuffer, str.size () + 1 , str.data (), str.size () );
383+ if ( error ) {
384+
385+ std::vector<char > errnoBuffer {};
386+ try {
387+
388+ errnoBuffer.resize ( errnoBufferSize );
389+ }
390+ catch ( const std::bad_alloc &_exception ) {
391+
392+ logFatal () << " bad_alloc:" << _exception.what ();
393+ }
394+ catch ( const std::exception &_exception ) {
395+
396+ logFatal () << _exception.what ();
397+ }
398+ std::ignore = strerror_s ( errnoBuffer.data (), errnoBuffer.size (), error );
399+ logError () << std::string ( std::cbegin ( errnoBuffer ), std::cend ( errnoBuffer ) );
400+ }
379401#else
380402 std::strncpy ( databuffer, str.data (), str.size () );
381403#endif
0 commit comments