Remove uses of stpcpy()

This function was only standardized in POSIX.1-2008, is not part of any ISO C standard, and is generally considered unsafe. Use SDL_strlcpy() instead.
This commit is contained in:
Frank Praznik
2026-09-08 13:54:26 -04:00
parent f48fa604b0
commit 184a070c5f
2 changed files with 10 additions and 4 deletions

View File

@@ -589,6 +589,8 @@ static void SelectionOfferNotifyFromMIMEs(SDL_WaylandDataDevice *data_device, bo
// Second pass to fill.
char *strPtr = (char *)(new_mime_types + num_formats + 1);
alloc_size -= (uintptr_t)strPtr - (uintptr_t)new_mime_types;
item = NULL;
int i = 0;
wl_list_for_each(item, &offer->mimes, link) {
@@ -596,9 +598,10 @@ static void SelectionOfferNotifyFromMIMEs(SDL_WaylandDataDevice *data_device, bo
continue;
}
new_mime_types[i] = strPtr;
strPtr = stpcpy(strPtr, item->mime_type) + 1;
i++;
new_mime_types[i++] = strPtr;
const size_t len = SDL_strlcpy(strPtr, item->mime_type, alloc_size) + 1;
strPtr += len;
alloc_size -= len;
}
new_mime_types[num_formats] = NULL;
}

View File

@@ -937,11 +937,14 @@ static void X11_HandleClipboardEvent(SDL_VideoDevice *_this, const XEvent *xeven
char **new_mime_types = SDL_AllocateTemporaryMemory(allocationsize);
if (new_mime_types) {
char *strPtr = (char *)(new_mime_types + length + 1);
allocationsize -= (uintptr_t)strPtr - (uintptr_t)new_mime_types;
for (j = 0, patom = (Atom *)data; j < length; j++, patom++) {
char *atomStr = X11_XGetAtomName(display, *patom);
new_mime_types[j] = strPtr;
strPtr = stpcpy(strPtr, atomStr) + 1;
const size_t len = SDL_strlcpy(strPtr, atomStr, allocationsize) + 1;
strPtr += len;
allocationsize -= len;
X11_XFree(atomStr);
}
new_mime_types[length] = NULL;