xutility(2227):警告C4996:'的std :: _ Copy_impl“ [英] xutility(2227): warning C4996: 'std::_Copy_impl'

查看:444
本文介绍了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.0\vc\include\xutility(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.0\vc\include\xutility(2212): Siehe Deklaration von 'std::_Copy_impl'
1>          c:\users\perlig\documents\visual studio 2010\projects\restmanager\restmanager\**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>          ]

在警告消息说,code发生在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)

任何人有任何想法?

anybody got any idea?

推荐答案

我想你知道什么是警告的意思,但首先我介绍了警告,然后说要怎样做才能摆脱它。微软实施新的安全启用在其CRT,STL,MFC,...并标记老版pcated提供你一个提示的功能去$ P $设置功能,您应该迁移到新的安全版本。所以说,性病::复制是不安全的!怎么样?如下:

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 ::存档::迭代器:: 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 输入标志或添加编译来禁用此警告(如你这样做),但为什么编译不工作?

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?

原因是显而易见的,你用编译它有什么不对的范围,这个编译工作范围,你必须提防 xutility 在该pragma和每一件事都会正常工作。

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“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆