From 0bf7d15fa61ce052c645a7e90f74befd08f7f95e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 8 Oct 2023 12:46:28 +1100 Subject: [PATCH] Cleanup: replace strncpy with memcpy for buffers of a known size --- intern/ghost/intern/GHOST_SystemCocoa.mm | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index d3d36eb93a9..c03b05a542f 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -338,14 +338,14 @@ static GHOST_TKey convertKey(int rawCode, unichar recvChar) #define FIRSTFILEBUFLG 512 static bool g_hasFirstFile = false; -static char g_firstFileBuf[512]; +static char g_firstFileBuf[FIRSTFILEBUFLG]; -// TODO: Need to investigate this. -// Function called too early in creator.c to have g_hasFirstFile == true +/* TODO: Need to investigate this. + * Function called too early in creator.c to have g_hasFirstFile == true */ extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG]) { if (g_hasFirstFile) { - strncpy(buf, g_firstFileBuf, FIRSTFILEBUFLG - 1); + memcpy(buf, g_firstFileBuf, FIRSTFILEBUFLG); buf[FIRSTFILEBUFLG - 1] = '\0'; return 1; } @@ -1239,9 +1239,8 @@ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType break; } - strncpy((char *)temp_buff, - [droppedStr cStringUsingEncoding:NSUTF8StringEncoding], - pastedTextSize); + memcpy( + temp_buff, [droppedStr cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize); temp_buff[pastedTextSize] = '\0'; strArray->strings[i] = temp_buff; @@ -1260,10 +1259,8 @@ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType return GHOST_kFailure; } - strncpy((char *)temp_buff, - [droppedStr cStringUsingEncoding:NSUTF8StringEncoding], - pastedTextSize); - + memcpy( + temp_buff, [droppedStr cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize); temp_buff[pastedTextSize] = '\0'; eventData = (GHOST_TEventDataPtr)temp_buff; @@ -1469,7 +1466,7 @@ bool GHOST_SystemCocoa::handleOpenDocumentRequest(void *filepathStr) return GHOST_kFailure; } - strncpy(temp_buff, [filepath cStringUsingEncoding:NSUTF8StringEncoding], filenameTextSize); + memcpy(temp_buff, [filepath cStringUsingEncoding:NSUTF8StringEncoding], filenameTextSize); temp_buff[filenameTextSize] = '\0'; pushEvent(new GHOST_EventString( @@ -2024,8 +2021,7 @@ char *GHOST_SystemCocoa::getClipboard(bool /*selection*/) const return nullptr; } - strncpy(temp_buff, [textPasted cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize); - + memcpy(temp_buff, [textPasted cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize); temp_buff[pastedTextSize] = '\0'; if (temp_buff) {