Skip to content

Commit cab1f40

Browse files
committed
Concurrency: silence warning on Windows
Prefer `strncpy_s` over `strncpy` which triggers a warning. This function ensures that the copied string is null-terminated if the string fits or simply returns an empty string (`\0`) if the string does not fit. Prefer to use `_TRUNCATE` to copy as much of the name as fits and ensure that it is null-terminated.
1 parent 69c5a02 commit cab1f40

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

stdlib/public/Concurrency/TaskStatus.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,13 @@ void AsyncTask::pushInitialTaskName(const char* _taskName) {
654654
auto taskNameLen = strlen(_taskName);
655655
char* taskNameCopy = reinterpret_cast<char*>(
656656
_swift_task_alloc_specific(this, taskNameLen + 1/*null terminator*/));
657+
#if defined(_WIN32)
658+
static_cast<void>(strncpy_s(taskNameCopy, taskNameLen + 1,
659+
_taskName, _TRUNCATE));
660+
#else
657661
(void) strncpy(/*dst=*/taskNameCopy, /*src=*/_taskName, taskNameLen);
658662
taskNameCopy[taskNameLen] = '\0'; // make sure we null-terminate
663+
#endif
659664

660665
auto record =
661666
::new (allocation) TaskNameStatusRecord(taskNameCopy);

0 commit comments

Comments
 (0)