Skip to content

Commit 8c2fe9d

Browse files
committed
strcpy_s causes too many problems, use strncpy_s
1 parent 6b5e7d2 commit 8c2fe9d

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

IntelPresentMon/CommonUtilities/cli/CliFramework.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace pmon::util::cli
5656
for (auto pWideStr : std::span{ wargv, size_t(argc) }) {
5757
const auto narrow = str::ToNarrow(pWideStr);
5858
auto pNarrowStr = new char[narrow.size() + 1];
59-
strcpy_s(pNarrowStr, narrow.size() + 1, narrow.c_str());
59+
strncpy_s(pNarrowStr, narrow.size() + 1, narrow.c_str(), _TRUNCATE);
6060
stringPointerArray.push_back(pNarrowStr);
6161
}
6262
}

IntelPresentMon/Interprocess/source/IntrospectionTransfer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace pmon::ipc::intro
5151
const auto bufferSize = buffer_.size() + 1;
5252
content.pData = charAlloc.allocate(bufferSize);
5353
if (content.pData) {
54-
strcpy_s(const_cast<char*>(content.pData), bufferSize, buffer_.c_str());
54+
strncpy_s(const_cast<char*>(content.pData), bufferSize, buffer_.c_str(), _TRUNCATE);
5555
}
5656
// emplace to allocated self
5757
if (pSelf) {

IntelPresentMon/PresentMonMiddleware/ConcreteMiddleware.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ static void ReportMetrics(
899899
{
900900
case PM_METRIC_CPU_NAME:
901901
{
902-
strcpy_s(reinterpret_cast<char*>(&pBlob[blobOffset]), sizeInBytes, cachedCpuInfo[0].deviceName.c_str());
902+
strncpy_s(reinterpret_cast<char*>(&pBlob[blobOffset]), sizeInBytes, cachedCpuInfo[0].deviceName.c_str(), _TRUNCATE);
903903
}
904904
break;
905905
case PM_METRIC_CPU_VENDOR:
@@ -919,7 +919,7 @@ static void ReportMetrics(
919919
auto index = GetCachedGpuInfoIndex(deviceId);
920920
if (index.has_value())
921921
{
922-
strcpy_s(reinterpret_cast<char*>(&pBlob[blobOffset]), sizeInBytes, cachedGpuInfo[index.value()].deviceName.c_str());
922+
strncpy_s(reinterpret_cast<char*>(&pBlob[blobOffset]), sizeInBytes, cachedGpuInfo[index.value()].deviceName.c_str(), _TRUNCATE);
923923
}
924924
}
925925
break;
@@ -1122,7 +1122,7 @@ static void ReportMetrics(
11221122
switch (element.metric)
11231123
{
11241124
case PM_METRIC_APPLICATION:
1125-
strcpy_s(reinterpret_cast<char*>(&pBlob[element.dataOffset]), 260, swapChain.mLastPresent.application);
1125+
strncpy_s(reinterpret_cast<char*>(&pBlob[element.dataOffset]), 260, swapChain.mLastPresent.application, _TRUNCATE);
11261126
break;
11271127
case PM_METRIC_PRESENT_MODE:
11281128
reinterpret_cast<PM_PRESENT_MODE&>(pBlob[element.dataOffset]) = (PM_PRESENT_MODE)swapChain.mLastPresent.PresentMode;

IntelPresentMon/PresentMonMiddleware/FrameEventQuery.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace
8585
if constexpr (std::is_same_v<std::remove_extent_t<Type>, char>) {
8686
const auto val = (ctx.pSourceFrameData->*pSubstruct.*pMember)[inputIndex_];
8787
// TODO: only getting first character of application name. Hmmm.
88-
strcpy_s(reinterpret_cast<char*>(&pDestBlob[outputOffset_]), 260, &val);
88+
strncpy_s(reinterpret_cast<char*>(&pDestBlob[outputOffset_]), 260, &val, _TRUNCATE);
8989
}
9090
else {
9191
const auto val = (ctx.pSourceFrameData->*pSubstruct.*pMember)[inputIndex_];

IntelPresentMon/Streamer/StreamClient.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,12 @@ void StreamClient::CopyFrameData(uint64_t start_qpc,
318318
src_frame->present_event.last_present_qpc,
319319
GetQpcFrequency());
320320

321-
strcpy_s(dst_frame->application, src_frame->present_event.application);
321+
strncpy_s(dst_frame->application, src_frame->present_event.application, _TRUNCATE);
322322

323323
dst_frame->process_id = src_frame->present_event.ProcessId;
324324
dst_frame->swap_chain_address = src_frame->present_event.SwapChainAddress;
325-
strcpy_s(dst_frame->runtime,
326-
RuntimeToString(src_frame->present_event.Runtime));
325+
strncpy_s(dst_frame->runtime,
326+
RuntimeToString(src_frame->present_event.Runtime), _TRUNCATE);
327327
dst_frame->sync_interval = src_frame->present_event.SyncInterval;
328328
dst_frame->present_flags = src_frame->present_event.PresentFlags;
329329

IntelPresentMon/Versioning/PresentMonAPIVersion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace pmon::bid
1212
.patch = 0,
1313
.tag = "beta",
1414
};
15-
strcpy_s(ver.hash, BuildIdShortHash());
15+
strncpy_s(ver.hash, BuildIdShortHash(), _TRUNCATE);
1616
return ver;
1717
}
1818
}

0 commit comments

Comments
 (0)