From a4ccc9a7eef3aa10b0213cb4d47d58f0e8936932 Mon Sep 17 00:00:00 2001 From: Nick Banks Date: Tue, 28 Mar 2017 09:19:25 -0700 Subject: [PATCH] Remove _CRT_SECURE_NO_WARNINGS Usage (#1517) * Remove usage of deprecated/unsafe CRT functions. --- etc/visual-studio/libopenthread-windows.vcxproj | 1 + examples/platforms/posix/platform-posix.h | 1 - include/openthread-windows-config.h | 3 --- src/ncp/ncp_uart.cpp | 6 +++--- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/etc/visual-studio/libopenthread-windows.vcxproj b/etc/visual-studio/libopenthread-windows.vcxproj index 28a0914d6..b3d924bcd 100644 --- a/etc/visual-studio/libopenthread-windows.vcxproj +++ b/etc/visual-studio/libopenthread-windows.vcxproj @@ -39,6 +39,7 @@ Level3 %(PreprocessorDefinitions); + _CRT_SECURE_NO_WARNINGS; OPENTHREAD_CONFIG_FILE="openthread-windows-config.h"; OTBUILD; diff --git a/examples/platforms/posix/platform-posix.h b/examples/platforms/posix/platform-posix.h index a13098d65..91e281f14 100644 --- a/examples/platforms/posix/platform-posix.h +++ b/examples/platforms/posix/platform-posix.h @@ -42,7 +42,6 @@ #endif #if _WIN32 -#define _CRT_SECURE_NO_WARNINGS #include #include #include diff --git a/include/openthread-windows-config.h b/include/openthread-windows-config.h index 52726ec0b..6440daf4b 100644 --- a/include/openthread-windows-config.h +++ b/include/openthread-windows-config.h @@ -98,9 +98,6 @@ // Redefine rand to random for test code #define random rand -// Temporary !!! TODO - Remove this once we figure out the strncpy issue -#define _CRT_SECURE_NO_WARNINGS - #ifdef OTBUILD #include #include diff --git a/src/ncp/ncp_uart.cpp b/src/ncp/ncp_uart.cpp index 1b66164af..10d04901a 100644 --- a/src/ncp/ncp_uart.cpp +++ b/src/ncp/ncp_uart.cpp @@ -223,7 +223,7 @@ void NcpUart::HandleError(ThreadError aError, uint8_t *aBuf, uint16_t aBufLength // We can get away with sprintf because we know // `hexbuf` is large enough. - sprintf(hexbuf, "Framing error %d: [", aError); + snprintf(hexbuf, sizeof(hexbuf), "Framing error %d: [", aError); // Write out the first part of our log message. otNcpStreamWrite(0, reinterpret_cast(hexbuf), static_cast(strlen(hexbuf))); @@ -235,12 +235,12 @@ void NcpUart::HandleError(ThreadError aError, uint8_t *aBuf, uint16_t aBufLength // We can get away with sprintf because we know // `hexbuf` is large enough, based on our calculations // above. - sprintf(&hexbuf[i*3], " %02X", static_cast(aBuf[i])); + snprintf(&hexbuf[i*3], sizeof(hexbuf) - i*3, " %02X", static_cast(aBuf[i])); } // Append a final closing bracket and newline character // so our log line looks nice. - sprintf(&hexbuf[i*3], "]\n"); + snprintf(&hexbuf[i*3], sizeof(hexbuf) - i*3, "]\n"); // Write out the second part of our log message. // We skip the first byte since it has a space in it.