簡體   English   中英

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

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

我收到了這條警告信息..但我不知道問題在哪里/哪里..!

包括

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

警告消息說,代碼出現在第257行。 但我無法解決它,因為我不知道有什么問題。

字符串數據包含一個“user:password”字符串,用於通過http進行基本身份驗證。

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是不安全的! 怎么樣? 如下:

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

現在如果用戶輸入超過10 int會發生什么? 內存將被覆蓋,你的內存已損壞。

使用boost::archive::iterators::ostream_iterator是完全安全的,但由於它不遵循MSVC中安全迭代器的設計,因此它將被視為不安全。

現在您應該通過-D_SCL_SECURE_NO_WARNINGS禁用此警告以cl輸入標志或添加pragma以禁用此警告(就像您一樣),但為什么pragma不起作用?

原因很明顯,這個pragma在范圍和你使用pragma的范圍上的工作都沒有錯,你必須用這個pragma保護xutility並且每個東西都會按預期工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM