Skip to content

Commit a92f379

Browse files
authored
[freestanding] prefer strncpy with known length (#80005)
1 parent 76a1742 commit a92f379

5 files changed

+8
-6
lines changed

stdlib/public/Concurrency/TaskStatus.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,11 @@ void AsyncTask::pushInitialTaskName(const char* _taskName) {
793793
this, sizeof(class TaskNameStatusRecord));
794794

795795
// TODO: Copy the string maybe into the same allocation at an offset or retain the swift string?
796+
auto taskNameLen = strlen(_taskName);
796797
char* taskNameCopy = reinterpret_cast<char*>(
797-
_swift_task_alloc_specific(this, strlen(_taskName) + 1/*null terminator*/));
798-
(void) strcpy(/*dst=*/taskNameCopy, /*src=*/_taskName);
798+
_swift_task_alloc_specific(this, taskNameLen + 1/*null terminator*/));
799+
(void) strncpy(/*dst=*/taskNameCopy, /*src=*/_taskName, taskNameLen);
800+
taskNameCopy[taskNameLen] = '\0'; // make sure we null-terminate
799801

800802
auto record =
801803
::new (allocation) TaskNameStatusRecord(taskNameCopy);

test/embedded/dependencies-concurrency-custom-executor.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// DEP: _putchar
2727
// DEP: _puts
2828
// DEP: _strlen
29-
// DEP: _strcpy
29+
// DEP: _strncpy
3030
// DEP: _vprintf
3131
// DEP: _vsnprintf
3232

test/embedded/dependencies-concurrency-custom-executor2.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// DEP: _putchar
2626
// DEP: _puts
2727
// DEP: _strlen
28-
// DEP: _strcpy
28+
// DEP: _strncpy
2929
// DEP: _vprintf
3030
// DEP: _vsnprintf
3131

test/embedded/dependencies-concurrency.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// DEP: _putchar
2727
// DEP: _puts
2828
// DEP: _strlen
29-
// DEP: _strcpy
29+
// DEP: _strncpy
3030
// DEP: _vprintf
3131
// DEP: _vsnprintf
3232

test/embedded/dependencies-concurrency2.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// DEP: _putchar
2424
// DEP: _puts
2525
// DEP: _strlen
26-
// DEP: _strcpy
26+
// DEP: _strncpy
2727
// DEP: _swift_task_asyncMainDrainQueueImpl
2828
// DEP: _swift_task_enqueueGlobalImpl
2929
// DEP: _swift_task_getMainExecutorImpl

0 commit comments

Comments
 (0)