Cleanup: remove strcpy usage

This commit is contained in:
Campbell Barton
2023-06-19 20:06:55 +10:00
parent 4a3b6bfeac
commit 8bcad285de
49 changed files with 168 additions and 171 deletions

View File

@@ -584,13 +584,14 @@ char *GHOST_GetTitle(GHOST_WindowHandle windowhandle)
GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
std::string title = window->getTitle();
char *ctitle = (char *)malloc(title.size() + 1);
const size_t ctitle_size = title.size() + 1;
char *ctitle = (char *)malloc(ctitle_size);
if (ctitle == nullptr) {
return nullptr;
}
strcpy(ctitle, title.c_str());
memcpy(ctitle, title.c_str(), ctitle_size);
return ctitle;
}

View File

@@ -2190,12 +2190,14 @@ char *GHOST_SystemX11::getClipboard(bool selection) const
owner = XGetSelectionOwner(m_display, sseln);
if (owner == win) {
if (sseln == m_atom.CLIPBOARD) {
sel_buf = (char *)malloc(strlen(txt_cut_buffer) + 1);
strcpy(sel_buf, txt_cut_buffer);
size_t sel_buf_size = strlen(txt_cut_buffer) + 1;
sel_buf = (char *)malloc(sel_buf_size);
memcpy(sel_buf, txt_cut_buffer, sel_buf_size);
return sel_buf;
}
sel_buf = (char *)malloc(strlen(txt_select_buffer) + 1);
strcpy(sel_buf, txt_select_buffer);
size_t sel_buf_size = strlen(txt_select_buffer) + 1;
sel_buf = (char *)malloc(sel_buf_size);
memcpy(sel_buf, txt_select_buffer, sel_buf_size);
return sel_buf;
}
if (owner == None) {
@@ -2289,8 +2291,9 @@ void GHOST_SystemX11::putClipboard(const char *buffer, bool selection) const
free((void *)txt_cut_buffer);
}
txt_cut_buffer = (char *)malloc(strlen(buffer) + 1);
strcpy(txt_cut_buffer, buffer);
size_t buffer_size = strlen(buffer) + 1;
txt_cut_buffer = (char *)malloc(buffer_size);
memcpy(txt_cut_buffer, buffer, buffer_size);
}
else {
XSetSelectionOwner(m_display, m_atom.PRIMARY, m_window, CurrentTime);
@@ -2299,8 +2302,9 @@ void GHOST_SystemX11::putClipboard(const char *buffer, bool selection) const
free((void *)txt_select_buffer);
}
txt_select_buffer = (char *)malloc(strlen(buffer) + 1);
strcpy(txt_select_buffer, buffer);
size_t buffer_size = strlen(buffer) + 1;
txt_select_buffer = (char *)malloc(buffer_size);
memcpy(txt_select_buffer, buffer, buffer_size);
}
if (owner != m_window) {