diff --git a/source/lib/precompiled.h b/source/lib/precompiled.h index a806731564..ed77557dc9 100755 --- a/source/lib/precompiled.h +++ b/source/lib/precompiled.h @@ -16,6 +16,10 @@ #pragma warning(disable:4786) // identifier truncated to 255 chars #endif +// make string_s (secure CRT string functions) available everywhere +#include "lib/string_s.h" + + // // memory headers // @@ -34,6 +38,7 @@ #include // uses placement new #include + // // headers to be precompiled // diff --git a/source/lib/string_s.cpp b/source/lib/string_s.cpp index f5ee055ce9..07568df5fa 100644 --- a/source/lib/string_s.cpp +++ b/source/lib/string_s.cpp @@ -194,9 +194,6 @@ int tcat_s(tchar* dst, size_t max_dst_chars, const tchar* src) static int test() { -debug_out("%s\n", __FILE__); -TIMER(stringtest); - const tchar* s0 = T(""); const tchar* s1 = T("a"); const tchar* s5 = T("abcde"); @@ -300,7 +297,7 @@ STMT( \ int ret = tcat_s((dst), dst_max, (src)); \ assert2(ret == expected_ret); \ if(dst != 0) \ - assert2(!tcmp(dst, expected_dst)); \ + assert2(!tcmp(dst, T(expected_dst))); \ ) #define TEST_CAT2(dst, dst_val, src, expected_ret, expected_dst) \ STMT( \ @@ -324,7 +321,7 @@ STMT( \ TEST_CAT(0 ,1,s1, EINVAL,""); // dst = 0, max > 0 TEST_CAT(d1,1,0 , EINVAL,""); // src = 0 TEST_CAT(d1,0,s1, ERANGE,""); // max_dst_chars = 0 - TEST_CAT(no_null,5,s1, ERANGE,T("")); // dst not terminated + TEST_CAT(no_null,5,s1, ERANGE,""); // dst not terminated TEST_CAT2(d1 ,"" ,s1, ERANGE,""); TEST_CAT2(d1 ,"" ,s5, ERANGE,""); diff --git a/source/lib/string_s.h b/source/lib/string_s.h index 09c92bf0b3..cecf221bee 100644 --- a/source/lib/string_s.h +++ b/source/lib/string_s.h @@ -1,6 +1,8 @@ #ifndef STRINGS_S_H__ #define STRINGS_S_H__ +#include "posix.h" // size_t + // these are already shipped with VC2005 #if _MSC_VER < 1400 @@ -9,8 +11,8 @@ // null character. to protect against access violations, only the // first characters are examined; if the null character is // not encountered by then, is returned. -extern size_t strlen_s(const tchar* str, size_t max_len); -extern size_t wcslen_s(const tchar* str, size_t max_len); +extern size_t strlen_s(const char* str, size_t max_len); +extern size_t wcslen_s(const wchar_t* str, size_t max_len); // copy at most (not including trailing null) from // into , which must not overlap. @@ -19,8 +21,8 @@ extern size_t wcslen_s(const tchar* str, size_t max_len); // 0 is returned to indicate success and that is null-terminated. // // note: padding with zeroes is not called for by NG1031. -extern int strncpy_s(tchar* dst, size_t max_dst_chars, const tchar* src, size_t max_src_chars); -extern int wcsncpy_s(tchar* dst, size_t max_dst_chars, const tchar* src, size_t max_src_chars); +extern int strncpy_s(char* dst, size_t max_dst_chars, const char* src, size_t max_src_chars); +extern int wcsncpy_s(wchar_t* dst, size_t max_dst_chars, const wchar_t* src, size_t max_src_chars); // copy (including trailing null) into , which must not overlap. // if thereby (including null) would be exceeded, @@ -28,16 +30,16 @@ extern int wcsncpy_s(tchar* dst, size_t max_dst_chars, const tchar* src, size_t // 0 is returned to indicate success and that is null-terminated. // // note: implemented as tncpy_s(dst, max_dst_chars, src, SIZE_MAX) -extern int strcpy_s(tchar* dst, size_t max_dst_chars, const tchar* src); -extern int wcscpy_s(tchar* dst, size_t max_dst_chars, const tchar* src); +extern int strcpy_s(char* dst, size_t max_dst_chars, const char* src); +extern int wcscpy_s(wchar_t* dst, size_t max_dst_chars, const wchar_t* src); // append at most (not including trailing null) from // to , which must not overlap. // if thereby (including null) would be exceeded, // is set to the empty string and ERANGE returned; otherwise, // 0 is returned to indicate success and that is null-terminated. -extern int strncat_s(tchar* dst, size_t max_dst_chars, const tchar* src, size_t max_src_chars); -extern int wcsncat_s(tchar* dst, size_t max_dst_chars, const tchar* src, size_t max_src_chars); +extern int strncat_s(char* dst, size_t max_dst_chars, const char* src, size_t max_src_chars); +extern int wcsncat_s(wchar_t* dst, size_t max_dst_chars, const wchar_t* src, size_t max_src_chars); // append to , which must not overlap. // if thereby (including null) would be exceeded, @@ -45,8 +47,8 @@ extern int wcsncat_s(tchar* dst, size_t max_dst_chars, const tchar* src, size_t // 0 is returned to indicate success and that is null-terminated. // // note: implemented as tncat_s(dst, max_dst_chars, src, SIZE_MAX) -extern int strcat_s(tchar* dst, size_t max_dst_chars, const tchar* src); -extern int wcscat_s(tchar* dst, size_t max_dst_chars, const tchar* src); +extern int strcat_s(char* dst, size_t max_dst_chars, const char* src); +extern int wcscat_s(wchar_t* dst, size_t max_dst_chars, const wchar_t* src); #endif // #if _MSC_VER < 1400