Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wrong buffer size in path string conversion functions #746

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions include/boost/gil/io/path_spec.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//
// Copyright 2007-2008 Andreas Pokorny, Christian Henning
// Copyright 2024 Dirk Stolle (minor fixes)
striezel marked this conversation as resolved.
Show resolved Hide resolved
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
Expand Down Expand Up @@ -41,9 +42,11 @@ inline std::string convert_to_string( std::string const& obj)

inline std::string convert_to_string( std::wstring const& s )
{
std::size_t len = wcslen( s.c_str() );
char* c = reinterpret_cast<char*>( alloca( len ));
wcstombs( c, s.c_str(), len );
std::mbstate_t state = std::mbstate_t();
const wchar_t* str = s.c_str();
const std::size_t len = std::wcsrtombs(nullptr, &str, 0, &state);
char* c = reinterpret_cast<char*>( alloca( len + 1));
striezel marked this conversation as resolved.
Show resolved Hide resolved
wcstombs( c, s.c_str(), len + 1 );

return std::string( c, c + len );
}
Expand Down Expand Up @@ -80,7 +83,8 @@ inline char const* convert_to_native_string( const std::string& str )

inline char const* convert_to_native_string( const wchar_t* str )
{
std::size_t len = wcslen( str ) + 1;
std::mbstate_t state = std::mbstate_t();
const std::size_t len = std::wcsrtombs(nullptr, &str, 0, &state) + 1;
char* c = new char[len];
wcstombs( c, str, len );

Expand All @@ -89,7 +93,9 @@ inline char const* convert_to_native_string( const wchar_t* str )

inline char const* convert_to_native_string( std::wstring const& str )
{
std::size_t len = wcslen( str.c_str() ) + 1;
std::mbstate_t state = std::mbstate_t();
const wchar_t* wstr = str.c_str();
const std::size_t len = std::wcsrtombs(nullptr, &wstr, 0, &state) + 1;
char* c = new char[len];
wcstombs( c, str.c_str(), len );

Expand Down
Loading