@@ -1347,7 +1347,9 @@ char* ImStrdup(ImStr str)
13471347    size_t  len = IM_IMSTR_LENGTH (str);
13481348    void * buf = IM_ALLOC (len + 1 );
13491349    *((char *)buf + len) = 0 ;                //  str may not contain \0, it must be inserted manually.
1350-     return  (char *)memcpy (buf, (const  void *)str.Begin , len);
1350+     if  (len > 0 )
1351+         return  (char *)memcpy (buf, (const  void *)str.Begin , len);
1352+     return  (char *)buf;
13511353}
13521354
13531355char * ImStrdupcpy (char * dst, size_t * p_dst_size, ImStr src)
@@ -1362,7 +1364,9 @@ char* ImStrdupcpy(char* dst, size_t* p_dst_size, ImStr src)
13621364            *p_dst_size = src_size;
13631365    }
13641366    dst[src_size - 1 ] = 0 ;              //  str may not contain \0, it must be inserted manually.
1365-     return  (char *)memcpy (dst, (const  void *)src.Begin , src_size - 1 );
1367+     if  (src_size > 1 )
1368+         return  (char *)memcpy (dst, (const  void *)src.Begin , src_size - 1 );
1369+     return  dst;
13661370}
13671371
13681372char * ImStrdupcpy (char * dst, size_t * p_dst_size, const  char * src)
@@ -2213,7 +2217,8 @@ void ImGuiTextBuffer::append(ImStr str)
22132217    }
22142218
22152219    Buf.resize (needed_sz);
2216-     memcpy (&Buf[write_off - 1 ], str.Begin , (size_t )len);
2220+     if  (len > 0 )
2221+         memcpy (&Buf[write_off - 1 ], str.Begin , (size_t )len);
22172222    Buf[write_off - 1  + len] = 0 ;
22182223}
22192224
@@ -3289,7 +3294,8 @@ void ImGui::SetClipboardText(ImStr text)
32893294    {
32903295        int  len = (int )IM_IMSTR_LENGTH (text);
32913296        char * text_p = (char *)IM_ALLOC (len + 1 );
3292-         memcpy (text_p, text.Begin , len);
3297+         if  (len > 0 )
3298+             memcpy (text_p, text.Begin , len);
32933299        text_p[len] = 0 ;        //  text may not contain \0, it must be inserted manually.
32943300        g.IO .SetClipboardTextFn (g.IO .ClipboardUserData , text_p);
32953301        IM_FREE (text_p);
@@ -9630,22 +9636,27 @@ void ImGui::MarkIniSettingsDirty(ImGuiWindow* window)
96309636ImGuiWindowSettings* ImGui::CreateNewWindowSettings (ImStr name)
96319637{
96329638    ImGuiContext& g = *GImGui;
9639+     const  size_t  name_len = IM_IMSTR_LENGTH (name);
9640+     if  (!name_len)
9641+     {
9642+         IM_ASSERT (false  && " Name must not be empty." 
9643+         return  NULL ;
9644+     }
96339645
96349646#if  !IMGUI_DEBUG_INI_SETTINGS
96359647    //  Skip to the "###" marker if any. We don't skip past to match the behavior of GetID()
96369648    //  Preserve the full string when IMGUI_DEBUG_INI_SETTINGS is set to make .ini inspection easier.
96379649    if  (const  char * p = ImStrstr (name, " ###" 
96389650        name.Begin  = p;
96399651#endif 
9640-     const  size_t  name_len = IM_IMSTR_LENGTH (name);
96419652
96429653    //  Allocate chunk
96439654    const  size_t  chunk_size = sizeof (ImGuiWindowSettings) + name_len + 1 ;
96449655    ImGuiWindowSettings* settings = g.SettingsWindows .alloc_chunk (chunk_size);
96459656    IM_PLACEMENT_NEW (settings) ImGuiWindowSettings ();
96469657    settings->ID  = ImHashStr (name);
96479658    memcpy (settings->GetName (), name.Begin , name_len);
9648-     settings->GetName ()[name_len] = 0 ;        //  name may not contain \0, it must be inserted manually.
9659+     settings->GetName ()[name_len] = 0 ;           //  name may not contain \0, it must be inserted manually.
96499660
96509661    return  settings;
96519662}
0 commit comments