简体   繁体   English

xutility(2227):警告C4996:'std :: _ Copy_impl'

[英]xutility(2227): warning C4996: 'std::_Copy_impl'

I got this warning message.. but i dont know what/where the problem is..! 我收到了这条警告信息..但我不知道问题在哪里/哪里..!

includes 包括

#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)

and the warning 和警告

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>          ]

the code occur in line 257 as the warning message says. 警告消息说,代码出现在第257行。 but i´m not able to fix it because i not know what is wrong.. 但我无法解决它,因为我不知道有什么问题。

string data contains a "user:password" string for basic auth via http. 字符串数据包含一个“user:password”字符串,用于通过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? 有谁有任何想法?

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. Microsoft在其CRT,STL,MFC等中实现了一组新的安全功能,并将这些功能的旧版本标记为已弃用,以便为您提供应迁移到新安全版本的提示。 so it say std::copy is unsafe!! 所以它说std :: copy是不安全的! how? 怎么样? as follow: 如下:

char storage[ 10 ], *p = storage;
std::copy( std::istream_iterator<int>(std::cin), std::istream_iterator<int>(), p );

Now what will happened if user input more than 10 int? 现在如果用户输入超过10 int会发生什么? the memory will be overwritten and you corrupted your memory. 内存将被覆盖,你的内存已损坏。

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. 使用boost::archive::iterators::ostream_iterator是完全安全的,但由于它不遵循MSVC中安全迭代器的设计,因此它将被视为不安全。

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? 现在您应该通过-D_SCL_SECURE_NO_WARNINGS禁用此警告以cl输入标志或添加pragma以禁用此警告(就像您一样),但为什么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. 原因很明显,这个pragma在范围和你使用pragma的范围上的工作都没有错,你必须用这个pragma保护xutility并且每个东西都会按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM