From edb7ba7437aa577d65da942aaf778c16c9a501ed Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 8 Feb 2015 11:48:37 +0200 Subject: Recode strncpy as memcpy VC12 deprecated those hard, as in, it is now an error. --- common/query/array/test.hxx | 9 +++++---- mssql/types/test.hxx | 12 ++++++------ mysql/types/test.hxx | 6 +++--- oracle/types/test.hxx | 6 +++--- pgsql/types/test.hxx | 6 +++--- sqlite/types/test.hxx | 8 ++++---- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/common/query/array/test.hxx b/common/query/array/test.hxx index 1bebf19..a881e8c 100644 --- a/common/query/array/test.hxx +++ b/common/query/array/test.hxx @@ -7,7 +7,7 @@ #include // HAVE_CXX11 -#include // std::strncpy +#include // std::memcpy, std::strlen #ifdef HAVE_CXX11 # include @@ -22,10 +22,11 @@ struct object object (unsigned long id, const char* s, const char* b) : id_ (id) { - std::strncpy (s_, s, sizeof (s_)); - std::strncpy (s1_, s, sizeof (s1_)); + std::memcpy (s_, s, std::strlen (s) + 1); // VC++ strncpy deprecation. + std::memcpy (s1_, s, std::strlen (s) + 1); + #ifdef HAVE_CXX11 - std::strncpy (a_.data (), s, a_.size ()); + std::memcpy (a_.data (), s, std::strlen (s) + 1); #endif c_ = c1_ = *s; std::memcpy (b_, b, sizeof (b_)); diff --git a/mssql/types/test.hxx b/mssql/types/test.hxx index 0b4653e..15070e3 100644 --- a/mssql/types/test.hxx +++ b/mssql/types/test.hxx @@ -23,8 +23,8 @@ typedef struct _GUID #include #include #include // std::auto_ptr -#include // std::memcmp, std::strncpy, std::str[n]cmp -#include // std::wcsncpy, std::wcs[n]cmp +#include // std::memcmp, std::memcpy, std::str[n]cmp, std::strlen +#include // std::wcslen, std::wcs[n]cmp #include @@ -379,12 +379,12 @@ struct char_array char_array (unsigned long id, const char* s, const wchar_t* ws) : id_ (id) { - std::strncpy (s1, s, sizeof (s1)); - std::strncpy (s2, s, sizeof (s2)); + std::memcpy (s1, s, std::strlen (s) + 1); // VC++ strncpy deprecation. + std::memcpy (s2, s, std::strlen (s) + 1); s3[0] = c1 = *s; - std::wcsncpy (ws1, ws, sizeof (ws1) / sizeof(wchar_t)); - std::wcsncpy (ws2, ws, sizeof (ws2) / sizeof(wchar_t)); + std::memcpy (ws1, ws, (std::wcslen (ws) + 1) * sizeof (wchar_t)); + std::memcpy (ws2, ws, (std::wcslen (ws) + 1) * sizeof (wchar_t)); ws3[0] = wc1 = *ws; if (std::strlen (s) == sizeof (s2)) diff --git a/mysql/types/test.hxx b/mysql/types/test.hxx index 5e6c7b4..aaf6df7 100644 --- a/mysql/types/test.hxx +++ b/mysql/types/test.hxx @@ -9,7 +9,7 @@ #include #include #include // std::auto_ptr -#include // std::strncpy, std::str[n]cmp +#include // std::memcpy, std::str[n]cmp, std::strlen #include @@ -282,8 +282,8 @@ struct char_array char_array (unsigned long id, const char* s) : id_ (id) { - std::strncpy (s1, s, sizeof (s1)); - std::strncpy (s2, s, sizeof (s2)); + std::memcpy (s1, s, std::strlen (s) + 1); // VC++ strncpy deprecation. + std::memcpy (s2, s, std::strlen (s) + 1); s3[0] = c1 = *s; } diff --git a/oracle/types/test.hxx b/oracle/types/test.hxx index 804f0aa..687f05e 100644 --- a/oracle/types/test.hxx +++ b/oracle/types/test.hxx @@ -8,7 +8,7 @@ #include #include #include // std::auto_ptr -#include // std::strncpy, std::str[n]cmp +#include // std::memcpy, std::str[n]cmp, std::strlen #include @@ -314,8 +314,8 @@ struct char_array char_array (unsigned long id, const char* s) : id_ (id) { - std::strncpy (s1, s, sizeof (s1)); - std::strncpy (s2, s, sizeof (s2)); + std::memcpy (s1, s, std::strlen (s) + 1); // VC++ strncpy deprecation. + std::memcpy (s2, s, std::strlen (s) + 1); s3[0] = c1 = *s; } diff --git a/pgsql/types/test.hxx b/pgsql/types/test.hxx index f3a7d26..773742e 100644 --- a/pgsql/types/test.hxx +++ b/pgsql/types/test.hxx @@ -9,7 +9,7 @@ #include #include #include // std::auto_ptr -#include // std::memcmp, std::strncpy, std::str[n]cmp +#include // std::memcmp, std::memcpy, std::str[n]cmp, std::strlen #include // std::size_t #include @@ -191,8 +191,8 @@ struct char_array char_array (unsigned long id, const char* s) : id_ (id) { - std::strncpy (s1, s, sizeof (s1)); - std::strncpy (s2, s, sizeof (s2)); + std::memcpy (s1, s, std::strlen (s) + 1); // VC++ strncpy deprecation. + std::memcpy (s2, s, std::strlen (s) + 1); s3[0] = c1 = *s; } diff --git a/sqlite/types/test.hxx b/sqlite/types/test.hxx index 5797089..5a0bb41 100644 --- a/sqlite/types/test.hxx +++ b/sqlite/types/test.hxx @@ -9,10 +9,10 @@ #include #include #include // std::auto_ptr -#include // std::strncpy, std::str[n]cmp +#include // std::memcpy, std::str[n]cmp, std::strlen #ifdef _WIN32 -# include // std::wcsncpy, std::wcs[n]cmp +# include // std::wcslen, std::wcs[n]cmp #endif #include @@ -85,11 +85,11 @@ struct char_array ) : id_ (id) { - std::strncpy (s1, s, sizeof (s1)); + std::memcpy (s1, s, std::strlen (s) + 1); // VC++ strncpy deprecation. s2[0] = c1 = *s; #ifdef _WIN32 - std::wcsncpy (ws1, ws, sizeof (ws1) / 2); + std::memcpy (ws1, ws, (std::wcslen (ws) + 1) * sizeof (wchar_t)); ws2[0] = wc1 = *ws; #endif } -- cgit v1.1