Skip to content

Commit

Permalink
-Wclass-memaccess
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Romain committed Dec 31, 2024
1 parent 69f55f3 commit a30b071
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 44 deletions.
16 changes: 8 additions & 8 deletions src/vendor/ImGui/imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -2095,13 +2095,13 @@ struct ImVector

inline int _grow_capacity(int sz) const { int new_capacity = Capacity ? (Capacity + Capacity / 2) : 8; return new_capacity > sz ? new_capacity : sz; }
inline void resize(int new_size) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); Size = new_size; }
inline void resize(int new_size, const T& v) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); if (new_size > Size) for (int n = Size; n < new_size; n++) memcpy(&Data[n], &v, sizeof(v)); Size = new_size; }
inline void resize(int new_size, const T& v) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); if (new_size > Size) for (int n = Size; n < new_size; n++) memcpy((void*)&Data[n], &v, sizeof(v)); Size = new_size; }
inline void shrink(int new_size) { IM_ASSERT(new_size <= Size); Size = new_size; } // Resize a vector to a smaller size, guaranteed not to cause a reallocation
inline void reserve(int new_capacity) { if (new_capacity <= Capacity) return; T* new_data = (T*)IM_ALLOC((size_t)new_capacity * sizeof(T)); if (Data) { memcpy(new_data, Data, (size_t)Size * sizeof(T)); IM_FREE(Data); } Data = new_data; Capacity = new_capacity; }
inline void reserve(int new_capacity) { if (new_capacity <= Capacity) return; T* new_data = (T*)IM_ALLOC((size_t)new_capacity * sizeof(T)); if (Data) { memcpy((void*)new_data, Data, (size_t)Size * sizeof(T)); IM_FREE(Data); } Data = new_data; Capacity = new_capacity; }
inline void reserve_discard(int new_capacity) { if (new_capacity <= Capacity) return; if (Data) IM_FREE(Data); Data = (T*)IM_ALLOC((size_t)new_capacity * sizeof(T)); Capacity = new_capacity; }

// NB: It is illegal to call push_back/push_front/insert with a reference pointing inside the ImVector data itself! e.g. v.push_back(v[10]) is forbidden.
inline void push_back(const T& v) { if (Size == Capacity) reserve(_grow_capacity(Size + 1)); memcpy(&Data[Size], &v, sizeof(v)); Size++; }
inline void push_back(const T& v) { if (Size == Capacity) reserve(_grow_capacity(Size + 1)); memcpy((void*)&Data[Size], &v, sizeof(v)); Size++; }
inline void pop_back() { IM_ASSERT(Size > 0); Size--; }
inline void push_front(const T& v) { if (Size == 0) push_back(v); else insert(Data, v); }
inline T* erase(const T* it) { IM_ASSERT(it >= Data && it < Data + Size); const ptrdiff_t off = it - Data; memmove(Data + off, Data + off + 1, ((size_t)Size - (size_t)off - 1) * sizeof(T)); Size--; return Data + off; }
Expand Down Expand Up @@ -2920,7 +2920,7 @@ struct ImDrawCmd
ImDrawCallback UserCallback; // 4-8 // If != NULL, call the function instead of rendering the vertices. clip_rect and texture_id will be set normally.
void* UserCallbackData; // 4-8 // The draw callback code can access this.

ImDrawCmd() { memset(this, 0, sizeof(*this)); } // Also ensure our padding fields are zeroed
ImDrawCmd() { memset((void*)this, 0, sizeof(*this)); } // Also ensure our padding fields are zeroed

// Since 1.83: returns ImTextureID associated with this draw call. Warning: DO NOT assume this is always same as 'TextureId' (we will change this function for an upcoming feature)
inline ImTextureID GetTexID() const { return TextureId; }
Expand Down Expand Up @@ -2966,7 +2966,7 @@ struct ImDrawListSplitter
int _Count; // Number of active channels (1+)
ImVector<ImDrawChannel> _Channels; // Draw channels (not resized down so _Count might be < Channels.Size)

inline ImDrawListSplitter() { memset(this, 0, sizeof(*this)); }
inline ImDrawListSplitter() { memset((void*)this, 0, sizeof(*this)); }
inline ~ImDrawListSplitter() { ClearFreeMemory(); }
inline void Clear() { _Current = 0; _Count = 1; } // Do not clear Channels[] so our allocations are reused next frame
IMGUI_API void ClearFreeMemory();
Expand Down Expand Up @@ -3037,7 +3037,7 @@ struct ImDrawList
const char* _OwnerName; // Pointer to owner window's name for debugging

// If you want to create ImDrawList instances, pass them ImGui::GetDrawListSharedData() or create and use your own ImDrawListSharedData (so you can use ImDrawList without ImGui)
ImDrawList(ImDrawListSharedData* shared_data) { memset(this, 0, sizeof(*this)); _Data = shared_data; }
ImDrawList(ImDrawListSharedData* shared_data) { memset((void*)this, 0, sizeof(*this)); _Data = shared_data; }

~ImDrawList() { _ClearFreeMemory(); }
IMGUI_API void PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_current_clip_rect = false); // Render-level scissoring. This is passed down to your render function but not used for CPU-side coarse clipping. Prefer using higher-level ImGui::PushClipRect() to affect logic (hit-testing and widget culling)
Expand Down Expand Up @@ -3465,7 +3465,7 @@ struct ImGuiViewport
void* PlatformHandle; // void* to hold higher-level, platform window handle (e.g. HWND, GLFWWindow*, SDL_Window*)
void* PlatformHandleRaw; // void* to hold lower-level, platform-native window handle (under Win32 this is expected to be a HWND, unused for other platforms)

ImGuiViewport() { memset(this, 0, sizeof(*this)); }
ImGuiViewport() { memset((void*)this, 0, sizeof(*this)); }

// Helpers
ImVec2 GetCenter() const { return ImVec2(Pos.x + Size.x * 0.5f, Pos.y + Size.y * 0.5f); }
Expand Down Expand Up @@ -3514,7 +3514,7 @@ struct ImGuiPlatformImeData
ImVec2 InputPos; // Position of the input cursor
float InputLineHeight; // Line height

ImGuiPlatformImeData() { memset(this, 0, sizeof(*this)); }
ImGuiPlatformImeData() { memset((void*)this, 0, sizeof(*this)); }
};

//-----------------------------------------------------------------------------
Expand Down
26 changes: 13 additions & 13 deletions src/vendor/ImGui/imgui_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ void ImGui::StyleColorsLight(ImGuiStyle* dst)

ImDrawListSharedData::ImDrawListSharedData()
{
memset(this, 0, sizeof(*this));
memset((void*)this, 0, sizeof(*this));
for (int i = 0; i < IM_ARRAYSIZE(ArcFastVtx); i++)
{
const float a = ((float)i * 2 * IM_PI) / (float)IM_ARRAYSIZE(ArcFastVtx);
Expand Down Expand Up @@ -408,7 +408,7 @@ void ImDrawList::_ResetForNewFrame()
IdxBuffer.resize(0);
VtxBuffer.resize(0);
Flags = _Data->InitialFlags;
memset(&_CmdHeader, 0, sizeof(_CmdHeader));
memset((void*)&_CmdHeader, 0, sizeof(_CmdHeader));
_VtxCurrentIdx = 0;
_VtxWritePtr = NULL;
_IdxWritePtr = NULL;
Expand Down Expand Up @@ -489,7 +489,7 @@ void ImDrawList::AddCallback(ImDrawCallback callback, void* callback_data)
// Compare ClipRect, TextureId and VtxOffset with a single memcmp()
#define ImDrawCmd_HeaderSize (offsetof(ImDrawCmd, VtxOffset) + sizeof(unsigned int))
#define ImDrawCmd_HeaderCompare(CMD_LHS, CMD_RHS) (memcmp(CMD_LHS, CMD_RHS, ImDrawCmd_HeaderSize)) // Compare ClipRect, TextureId, VtxOffset
#define ImDrawCmd_HeaderCopy(CMD_DST, CMD_SRC) (memcpy(CMD_DST, CMD_SRC, ImDrawCmd_HeaderSize)) // Copy ClipRect, TextureId, VtxOffset
#define ImDrawCmd_HeaderCopy(CMD_DST, CMD_SRC) (memcpy((void*)CMD_DST, CMD_SRC, ImDrawCmd_HeaderSize)) // Copy ClipRect, TextureId, VtxOffset
#define ImDrawCmd_AreSequentialIdxOffset(CMD_0, CMD_1) (CMD_0->IdxOffset + CMD_0->ElemCount == CMD_1->IdxOffset)

// Try to merge two last draw commands
Expand Down Expand Up @@ -2041,7 +2041,7 @@ void ImDrawListSplitter::ClearFreeMemory()
for (int i = 0; i < _Channels.Size; i++)
{
if (i == _Current)
memset(&_Channels[i], 0, sizeof(_Channels[i])); // Current channel is a copy of CmdBuffer/IdxBuffer, don't destruct again
memset((void*)&_Channels[i], 0, sizeof(_Channels[i])); // Current channel is a copy of CmdBuffer/IdxBuffer, don't destruct again
_Channels[i]._CmdBuffer.clear();
_Channels[i]._IdxBuffer.clear();
}
Expand All @@ -2065,7 +2065,7 @@ void ImDrawListSplitter::Split(ImDrawList* draw_list, int channels_count)
// Channels[] (24/32 bytes each) hold storage that we'll swap with draw_list->_CmdBuffer/_IdxBuffer
// The content of Channels[0] at this point doesn't matter. We clear it to make state tidy in a debugger but we don't strictly need to.
// When we switch to the next channel, we'll copy draw_list->_CmdBuffer/_IdxBuffer into Channels[0] and then Channels[1] into draw_list->CmdBuffer/_IdxBuffer
memset(&_Channels[0], 0, sizeof(ImDrawChannel));
memset((void*)&_Channels[0], 0, sizeof(ImDrawChannel));
for (int i = 1; i < channels_count; i++)
{
if (i >= old_channels_count)
Expand Down Expand Up @@ -2158,11 +2158,11 @@ void ImDrawListSplitter::SetCurrentChannel(ImDrawList* draw_list, int idx)
return;

// Overwrite ImVector (12/16 bytes), four times. This is merely a silly optimization instead of doing .swap()
memcpy(&_Channels.Data[_Current]._CmdBuffer, &draw_list->CmdBuffer, sizeof(draw_list->CmdBuffer));
memcpy(&_Channels.Data[_Current]._IdxBuffer, &draw_list->IdxBuffer, sizeof(draw_list->IdxBuffer));
memcpy((void*)&_Channels.Data[_Current]._CmdBuffer, &draw_list->CmdBuffer, sizeof(draw_list->CmdBuffer));
memcpy((void*)&_Channels.Data[_Current]._IdxBuffer, &draw_list->IdxBuffer, sizeof(draw_list->IdxBuffer));
_Current = idx;
memcpy(&draw_list->CmdBuffer, &_Channels.Data[idx]._CmdBuffer, sizeof(draw_list->CmdBuffer));
memcpy(&draw_list->IdxBuffer, &_Channels.Data[idx]._IdxBuffer, sizeof(draw_list->IdxBuffer));
memcpy((void*)&draw_list->CmdBuffer, &_Channels.Data[idx]._CmdBuffer, sizeof(draw_list->CmdBuffer));
memcpy((void*)&draw_list->IdxBuffer, &_Channels.Data[idx]._IdxBuffer, sizeof(draw_list->IdxBuffer));
draw_list->_IdxWritePtr = draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size;

// If current command is used with different settings we need to add a new command
Expand Down Expand Up @@ -2332,7 +2332,7 @@ void ImGui::ShadeVertsTransformPos(ImDrawList* draw_list, int vert_start_idx, in

ImFontConfig::ImFontConfig()
{
memset(this, 0, sizeof(*this));
memset((void*)this, 0, sizeof(*this));
FontDataOwnedByAtlas = true;
OversampleH = 2;
OversampleV = 1;
Expand Down Expand Up @@ -2398,7 +2398,7 @@ static const ImVec2 FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[ImGuiMouseCursor_COUNT][3

ImFontAtlas::ImFontAtlas()
{
memset(this, 0, sizeof(*this));
memset((void*)this, 0, sizeof(*this));
TexGlyphPadding = 1;
PackIdMouseCursors = PackIdLines = -1;
}
Expand Down Expand Up @@ -2787,8 +2787,8 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
ImVector<ImFontBuildDstData> dst_tmp_array;
src_tmp_array.resize(atlas->ConfigData.Size);
dst_tmp_array.resize(atlas->Fonts.Size);
memset(src_tmp_array.Data, 0, (size_t)src_tmp_array.size_in_bytes());
memset(dst_tmp_array.Data, 0, (size_t)dst_tmp_array.size_in_bytes());
memset((void*)src_tmp_array.Data, 0, (size_t)src_tmp_array.size_in_bytes());
memset((void*)dst_tmp_array.Data, 0, (size_t)dst_tmp_array.size_in_bytes());

// 1. Initialize font loading structure, check font data validity
for (int src_i = 0; src_i < atlas->ConfigData.Size; src_i++)
Expand Down
34 changes: 17 additions & 17 deletions src/vendor/ImGui/imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ struct ImDrawDataBuilder
ImVector<ImDrawList*>* Layers[2]; // Pointers to global layers for: regular, tooltip. LayersP[0] is owned by DrawData.
ImVector<ImDrawList*> LayerData1;

ImDrawDataBuilder() { memset(this, 0, sizeof(*this)); }
ImDrawDataBuilder() { memset((void*)this, 0, sizeof(*this)); }
};

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1066,7 +1066,7 @@ struct IMGUI_API ImGuiComboPreviewData
float BackupPrevLineTextBaseOffset;
ImGuiLayoutType BackupLayout;

ImGuiComboPreviewData() { memset(this, 0, sizeof(*this)); }
ImGuiComboPreviewData() { memset((void*)this, 0, sizeof(*this)); }
};

// Stacked storage data for BeginGroup()/EndGroup()
Expand Down Expand Up @@ -1111,7 +1111,7 @@ struct IMGUI_API ImGuiInputTextDeactivatedState
ImGuiID ID; // widget id owning the text state (which just got deactivated)
ImVector<char> TextA; // text buffer

ImGuiInputTextDeactivatedState() { memset(this, 0, sizeof(*this)); }
ImGuiInputTextDeactivatedState() { memset((void*)this, 0, sizeof(*this)); }
void ClearFreeMemory() { ID = 0; TextA.clear(); }
};
// Internal state of the currently focused/edited text input box
Expand All @@ -1137,7 +1137,7 @@ struct IMGUI_API ImGuiInputTextState
int ReloadSelectionStart; // POSITIONS ARE IN IMWCHAR units *NOT* UTF-8 this is why this is not exposed yet.
int ReloadSelectionEnd;

ImGuiInputTextState() { memset(this, 0, sizeof(*this)); }
ImGuiInputTextState() { memset((void*)this, 0, sizeof(*this)); }
void ClearText() { CurLenW = CurLenA = 0; TextW[0] = 0; TextA[0] = 0; CursorClamp(); }
void ClearFreeMemory() { TextW.clear(); TextA.clear(); InitialTextA.clear(); }
int GetUndoAvailCount() const { return Stb.undostate.undo_point; }
Expand Down Expand Up @@ -1210,7 +1210,7 @@ struct ImGuiNextWindowData
ImVec2 MenuBarOffsetMinVal; // (Always on) This is not exposed publicly, so we don't clear it and it doesn't have a corresponding flag (could we? for consistency?)
ImGuiWindowRefreshFlags RefreshFlagsVal;

ImGuiNextWindowData() { memset(this, 0, sizeof(*this)); }
ImGuiNextWindowData() { memset((void*)this, 0, sizeof(*this)); }
inline void ClearFlags() { Flags = ImGuiNextWindowDataFlags_None; }
};

Expand Down Expand Up @@ -1256,7 +1256,7 @@ struct ImGuiLastItemData
ImRect ClipRect; // Clip rectangle at the time of submitting item. ONLY VALID IF (StatusFlags & ImGuiItemStatusFlags_HasClipRect) is set..
ImGuiKeyChord Shortcut; // Shortcut at the time of submitting item. ONLY VALID IF (StatusFlags & ImGuiItemStatusFlags_HasShortcut) is set..

ImGuiLastItemData() { memset(this, 0, sizeof(*this)); }
ImGuiLastItemData() { memset((void*)this, 0, sizeof(*this)); }
};

// Store data emitted by TreeNode() for usage by TreePop()
Expand Down Expand Up @@ -1336,7 +1336,7 @@ struct ImGuiPopupData
ImVec2 OpenPopupPos; // Set on OpenPopup(), preferred popup position (typically == OpenMousePos when using mouse)
ImVec2 OpenMousePos; // Set on OpenPopup(), copy of mouse position at the time of opening popup

ImGuiPopupData() { memset(this, 0, sizeof(*this)); ParentNavLayer = OpenFrameCount = -1; }
ImGuiPopupData() { memset((void*)this, 0, sizeof(*this)); ParentNavLayer = OpenFrameCount = -1; }
};

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1414,7 +1414,7 @@ struct ImGuiInputEvent
};
bool AddedByTestEngine;

ImGuiInputEvent() { memset(this, 0, sizeof(*this)); }
ImGuiInputEvent() { memset((void*)this, 0, sizeof(*this)); }
};

// Input function taking an 'ImGuiID owner_id' argument defaults to (ImGuiKeyOwner_Any == 0) aka don't test ownership, which matches legacy behavior.
Expand Down Expand Up @@ -1529,7 +1529,7 @@ struct ImGuiListClipperData
int ItemsFrozen;
ImVector<ImGuiListClipperRange> Ranges;

ImGuiListClipperData() { memset(this, 0, sizeof(*this)); }
ImGuiListClipperData() { memset((void*)this, 0, sizeof(*this)); }
void Reset(ImGuiListClipper* clipper) { ListClipper = clipper; StepNo = ItemsFrozen = 0; Ranges.resize(0); }
};

Expand Down Expand Up @@ -1692,7 +1692,7 @@ struct ImGuiOldColumnData
ImGuiOldColumnFlags Flags; // Not exposed
ImRect ClipRect;

ImGuiOldColumnData() { memset(this, 0, sizeof(*this)); }
ImGuiOldColumnData() { memset((void*)this, 0, sizeof(*this)); }
};

struct ImGuiOldColumns
Expand All @@ -1713,7 +1713,7 @@ struct ImGuiOldColumns
ImVector<ImGuiOldColumnData> Columns;
ImDrawListSplitter Splitter;

ImGuiOldColumns() { memset(this, 0, sizeof(*this)); }
ImGuiOldColumns() { memset((void*)this, 0, sizeof(*this)); }
};

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1741,7 +1741,7 @@ struct ImGuiBoxSelectState
ImRect BoxSelectRectPrev; // Selection rectangle in absolute coordinates (derived every frame from BoxSelectStartPosRel and MousePos)
ImRect BoxSelectRectCurr;

ImGuiBoxSelectState() { memset(this, 0, sizeof(*this)); }
ImGuiBoxSelectState() { memset((void*)this, 0, sizeof(*this)); }
};

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1847,7 +1847,7 @@ struct ImGuiWindowSettings
bool WantApply; // Set when loaded from .ini data (to enable merging/loading .ini data into an already running context)
bool WantDelete; // Set to invalidate/delete the settings entry

ImGuiWindowSettings() { memset(this, 0, sizeof(*this)); }
ImGuiWindowSettings() { memset((void*)this, 0, sizeof(*this)); }
char* GetName() { return (char*)(this + 1); }
};

Expand Down Expand Up @@ -1969,7 +1969,7 @@ struct ImGuiIDStackTool
bool CopyToClipboardOnCtrlC;
float CopyToClipboardLastTime;

ImGuiIDStackTool() { memset(this, 0, sizeof(*this)); CopyToClipboardLastTime = -FLT_MAX; }
ImGuiIDStackTool() { memset((void*)this, 0, sizeof(*this)); CopyToClipboardLastTime = -FLT_MAX; }
};

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -2863,7 +2863,7 @@ struct ImGuiTableColumn

ImGuiTableColumn()
{
memset(this, 0, sizeof(*this));
memset((void*)this, 0, sizeof(*this));
StretchWeight = WidthRequest = -1.0f;
NameOffset = -1;
DisplayOrder = IndexWithinEnabledSet = -1;
Expand Down Expand Up @@ -3023,7 +3023,7 @@ struct IMGUI_API ImGuiTable
bool MemoryCompacted;
bool HostSkipItems; // Backup of InnerWindow->SkipItem at the end of BeginTable(), because we will overwrite InnerWindow->SkipItem on a per-column basis

ImGuiTable() { memset(this, 0, sizeof(*this)); LastFrameActive = -1; }
ImGuiTable() { memset((void*)this, 0, sizeof(*this)); LastFrameActive = -1; }
~ImGuiTable() { IM_FREE(RawData); }
};

Expand Down Expand Up @@ -3051,7 +3051,7 @@ struct IMGUI_API ImGuiTableTempData
float HostBackupItemWidth; // Backup of OuterWindow->DC.ItemWidth at the end of BeginTable()
int HostBackupItemWidthStackSize;//Backup of OuterWindow->DC.ItemWidthStack.Size at the end of BeginTable()

ImGuiTableTempData() { memset(this, 0, sizeof(*this)); LastTimeActive = -1.0f; }
ImGuiTableTempData() { memset((void*)this, 0, sizeof(*this)); LastTimeActive = -1.0f; }
};

// sizeof() ~ 12
Expand Down
Loading

0 comments on commit a30b071

Please sign in to comment.