Skip to content

Commit 59ba8a5

Browse files
iscgarruevs
authored andcommitted
general: fix compiler warning about object construction and assignment
TextWindow uses memset to zero objects that have non-trivial constructors, in order to avoid assignment with a temporary which leads to an overflow of the stack. Replace it with an explicit destructor call and placement new.
1 parent cbcc5f5 commit 59ba8a5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/textwin.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//
44
// Copyright 2008-2013 Jonathan Westhues.
55
//-----------------------------------------------------------------------------
6+
#include <new>
67
#include "solvespace.h"
78

89
namespace SolveSpace {
@@ -283,16 +284,17 @@ void TextWindow::Init() {
283284
void TextWindow::ClearSuper() {
284285
// Ugly hack, but not so ugly as the next line
285286
Platform::WindowRef oldWindow = std::move(window);
286-
std::shared_ptr<ViewportCanvas> oldCanvas = canvas;
287+
std::shared_ptr<ViewportCanvas> oldCanvas = std::move(canvas);
287288

288289
// Cannot use *this = {} here because TextWindow instances
289290
// are 2.4MB long; this causes stack overflows in prologue
290291
// when built with MSVC, even with optimizations.
291-
memset(this, 0, sizeof(*this));
292+
this->~TextWindow();
293+
new(this) TextWindow();
292294

293295
// Return old canvas
294296
window = std::move(oldWindow);
295-
canvas = oldCanvas;
297+
canvas = std::move(oldCanvas);
296298

297299
HideEditControl();
298300

0 commit comments

Comments
 (0)