kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #38025
[PATCH 2/3] Allocate temporary buffer on the heap
Variable length arrays are not in the C++ standard, also it makes our stack
frame size unpredictable.
---
common/utf8.cpp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/common/utf8.cpp b/common/utf8.cpp
index 1895955806..76c40cef9d 100644
--- a/common/utf8.cpp
+++ b/common/utf8.cpp
@@ -27,6 +27,8 @@
#include <wx/strconv.h>
#include <wx/buffer.h>
+#include <memory>
+
/* THROW_IO_ERROR needs this, but it includes this file, so until some
factoring of THROW_IO_ERROR into a separate header, defer and use the asserts.
#include <richio.h>
@@ -204,9 +206,9 @@ UTF8::UTF8( const wchar_t* txt )
try
{
size_t len = wcslen( txt ) * 4 + 1;
- char temp[len];
- wxConvUTF8.WC2MB( temp, txt, len );
- m_s.assign( temp );
+ std::unique_ptr<char []> temp( new char[len] );
+ wxConvUTF8.WC2MB( temp.get(), txt, len );
+ m_s.assign( temp.get() );
}
catch(...)
{
References