-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MMDevice: Remove need for _CRT_SECURE_NO_WARNINGS
That is, remove use of strcpy(), strncpy(), and getenv(). Replace str[n]cpy() with snprintf(). Add tests in the case of CDeviceUtils::CopyLimitedString() (previous implementation had a bug where it didn't null-terminate if the source string was exactly MM::MaxStrLength - 1 chars long). The use of getenv() was dead code, so remove entirely.
- Loading branch information
1 parent
3e044e8
commit ef695e4
Showing
7 changed files
with
41 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <catch2/catch_all.hpp> | ||
|
||
#include "DeviceUtils.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
TEST_CASE("CopyLimitedString truncates", "[CopyLimitedString]") | ||
{ | ||
std::vector<char> dest(MM::MaxStrLength, '.'); | ||
const std::string src(MM::MaxStrLength + 10, '*'); | ||
CHECK_FALSE(CDeviceUtils::CopyLimitedString(dest.data(), src.c_str())); | ||
CHECK(dest[0] == '*'); | ||
CHECK(dest[MM::MaxStrLength - 2] == '*'); | ||
CHECK(dest[MM::MaxStrLength - 1] == '\0'); | ||
} | ||
|
||
TEST_CASE("CopyLimitedString max untruncated len", "[CopyLimitedString]") | ||
{ | ||
std::vector<char> dest(MM::MaxStrLength, '.'); | ||
const std::string src(MM::MaxStrLength - 1, '*'); | ||
CHECK(CDeviceUtils::CopyLimitedString(dest.data(), src.c_str())); | ||
CHECK(dest[0] == '*'); | ||
CHECK(dest[MM::MaxStrLength - 2] == '*'); | ||
CHECK(dest[MM::MaxStrLength - 1] == '\0'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters