Skip to content

Commit 3554574

Browse files
committed
Avoid using strncpy_s in two cases, and fix third
Fixes #15 - corecrt_internal_string_templates.h line 218 buffer is too small.
1 parent 8f10c5f commit 3554574

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/Path.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ bool getExecutablePathComponents()
234234
WARNING_PRINTF("unexpected length mismatch, GetModuleFileNameA %zu, strlen %zu\n", length, strlen(moduleFullPath));
235235
}
236236

237-
executableFullPath_.reserve(length + 1);
238-
executableFullPath_.resize(length);
239-
strncpy_s(&executableFullPath_[0], length + 1, moduleFullPath, length);
237+
executableFullPath_ = moduleFullPath;
240238
DEBUG_PRINTF("executable full path: %s\n", executableFullPath_.c_str());
241239

242240
CHAR * fileName = PathFindFileNameA(moduleFullPath);
@@ -259,10 +257,7 @@ bool getExecutablePathComponents()
259257
return false;
260258
}
261259

262-
length = strlen(moduleFullPath);
263-
executableDir_.reserve(length + 1);
264-
executableDir_.resize(length);
265-
strncpy_s(&executableDir_[0], length + 1, moduleFullPath, length);
260+
executableDir_ = moduleFullPath;
266261
DEBUG_PRINTF("executable dir: %s\n", executableDir_.c_str());
267262

268263
return true;

src/TrayIcon.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ void TrayIcon::updateTip(const std::string & tip)
9898
{
9999
if (nid_.uID) {
100100
DEBUG_PRINTF("updating tray icon %u tip to %s\n", nid_.uID, tip.c_str());
101-
strncpy_s(nid_.szTip, tip.c_str(), sizeof(nid_.szTip) / sizeof(nid_.szTip[0]));
101+
size_t tipMaxSize = sizeof(nid_.szTip) / sizeof(nid_.szTip[0]);
102+
strncpy_s(nid_.szTip, tip.c_str(), tipMaxSize - 1);
102103
if (!Shell_NotifyIconA(NIM_MODIFY, &nid_)) {
103104
WARNING_PRINTF(
104105
"could not update tray icon tip, Shell_NotifyIcon() failed: %s\n",

0 commit comments

Comments
 (0)