xutility(2227): warning C4996: #39;std::_Copy_impl#39;(xutility(2227): 警告 C4996: std::_Copy_impl)
问题描述
我收到此警告消息.. 但我不知道问题出在哪里/哪里..!
I got this warning message.. but i dont know what/where the problem is..!
包括
#pragma warning(push)
#pragma warning(disable:4996)
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/insert_linebreaks.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/archive/iterators/ostream_iterator.hpp>
#pragma warning(pop)
和警告
1>c:program files (x86)microsoft visual studio 10.0vcincludexutility(2227): warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> c:program files (x86)microsoft visual studio 10.0vcincludexutility(2212): Siehe Deklaration von 'std::_Copy_impl'
1> c:usersperligdocumentsvisual studio 2010projects
estmanager
estmanager**http.cpp(257)**: Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-template "_OutIt std::copy<boost::archive::iterators::insert_linebreaks<Base,N>,boost::archive::iterators::ostream_iterator<Elem>>(_InIt,_InIt,_OutIt)".
1> with
1> [
1> _OutIt=boost::archive::iterators::ostream_iterator<char>,
1> Base=boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<const char *,6,8>>,
1> N=76,
1> Elem=char,
1> _InIt=boost::archive::iterators::insert_linebreaks<boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<const char *,6,8>>,76>
1> ]
代码出现在第 257 行,如警告消息所述.但我无法修复它,因为我不知道出了什么问题..
the code occur in line 257 as the warning message says. but i´m not able to fix it because i not know what is wrong..
字符串数据包含一个用户:密码"字符串,用于通过 http 进行基本身份验证.
string data contains a "user:password" string for basic auth via http.
http.cpp(257):
http.cpp(257):
// typdef, prepare
using namespace boost::archive::iterators;
stringstream os;
typedef
insert_linebreaks< // insert line breaks every 72 characters
base64_from_binary< // convert binary values ot base64 characters
transform_width< // retrieve 6 bit integers from a sequence of 8 bit bytes
const char *,
6,
8
>
>
,76
>
base64_text; // compose all the above operations in to a new iterator
// encrypt
#pragma warning(push)
#pragma warning(disable:4996)
copy( //<<<<<------ LINE 257
base64_text(data.c_str()),
base64_text(data.c_str() + data.size()),
boost::archive::iterators::ostream_iterator<char>(os)
);
#pragma warning(pop)
有人知道吗?
推荐答案
我想你知道警告的含义是什么,但首先我描述了警告,然后说如何摆脱它.Microsoft 在其 CRT、STL、MFC 等中实现了一组新的启用安全功能的功能,并将这些功能的旧版本标记为已弃用,以提示您应该迁移到新的安全版本.所以它说 std::copy 不安全!如何?如下:
I think you know what is the meaning of the warning but first I describe the warning and then say what to do to get rid of it. Microsoft implemented a new security enabled set of function in its CRT, STL, MFC, ... and mark old version of those functions as deprecated to provide a hint for you that you should migrate to new secure version. so it say std::copy is unsafe!! how? as follow:
char storage[ 10 ], *p = storage;
std::copy( std::istream_iterator<int>(std::cin), std::istream_iterator<int>(), p );
现在如果用户输入超过 10 个 int 会发生什么?内存将被覆盖,您的内存被破坏了.
Now what will happened if user input more than 10 int? the memory will be overwritten and you corrupted your memory.
使用 boost::archive::iterators::ostream_iterator
是完全安全的,但由于它不遵循 MSVC 中安全迭代器的设计,因此将被视为不安全.
Using boost::archive::iterators::ostream_iterator
is perfectly safe but since it does not follow the design of safe iterators in MSVC it will considered as unsafe.
现在你应该通过 -D_SCL_SECURE_NO_WARNINGS
禁用这个警告到 cl
输入标志或添加一个 pragma
来禁用这个警告(就像你做的那样),但为什么 pragma 不起作用?
Now you should either disable this warning by -D_SCL_SECURE_NO_WARNINGS
to cl
input flags or add a pragma
to disable this warning( as you do ), but why pragma don't work?
原因很明显,这个 pragma 在作用域上起作用,你在它上面使用 pragma 的作用域没有错,你必须用这个 pragma 保护 xutility
,一切都会按预期工作.
the reason is obvious, this pragma work on scope and the scope that you use pragma on it have nothing wrong, you must guard xutility
with this pragma and every thing will work as expected.
这篇关于xutility(2227): 警告 C4996: 'std::_Copy_impl'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:xutility(2227): 警告 C4996: 'std::_Copy_impl'
基础教程推荐
- C++,'if' 表达式中的变量声明 2021-01-01
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 运算符重载的基本规则和习语是什么? 2022-10-31
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 设计字符串本地化的最佳方法 2022-01-01