c++ - 编译器错误 : Function call with parameters that may be unsafe

标签 c++ windows visual-studio-2005 warnings

得到了一些不是我的代码并且它产生了这个警告atm:

iehtmlwin.cpp(264) : warning C4996: 'std::basic_string<_Elem,_Traits,_Ax>::copy': 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'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>,
            _Ax=std::allocator<char>
        ]
        c:\program files (x86)\microsoft visual studio 8\vc\include\xstring(1680) : see declaration of 'std::basic_string<_Elem,_Traits,_Ax>::copy'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>,
            _Ax=std::allocator<char>
        ]

这是有问题的代码:

HRESULT STDMETHODCALLTYPE Read(void __RPC_FAR *pv, ULONG cb, ULONG __RPC_FAR *pcbRead)
    {
        if (prepend.size() > 0)
        {
            int n = min(prepend.size(), cb);
            prepend.copy((char *) pv, n);
            prepend = prepend.substr(n);
            if (pcbRead)
                *pcbRead = n;

            return S_OK;
        };

        int rc = Read((char *) pv, cb);
        if (pcbRead)
            *pcbRead = rc;

        return S_OK;
    };

警告指的是 prepend.copy 行。我试过用谷歌搜索警告,但无法弄清楚它是关于什么的。谁能帮我解决这个问题。

Visual Studio 2005 SP1 Windows 7 RC1

.

编辑:前置是一个类型定义的字符串

typedef basic_string<char, char_traits<char>, allocator<char> > string;

最佳答案

警告告诉您,如果 n 太大,您将面临缓冲区溢出的风险——您知道这不会发生,因为您刚刚使用 min,但可怜的编译器没有。我建议你采纳编译器自己的建议,对这个源文件使用 -D_SCL_SECURE_NO_WARNINGS...

关于c++ - 编译器错误 : Function call with parameters that may be unsafe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/903064/

相关文章:

c++ - 共享内存: MapViewOfFile returns error 5

c++ - Ubuntu 10.04 需要什么包才能运行用 gcc/g++ 4.7 编译的程序?

python - 是否有任何脚本可以将文件夹图像转换为一个 pdf

visual-studio-2005 - 在哪里可以找到 Visual Studio 宏示例?

visual-studio - Visual Studio 2005(和其他): how to deploy debug dll (msvcp80p. dll 和 friend ,用于调试目的)

c++ - C++ 中的 Dijkstra 算法

简单图像处理示例中的 C++AMP 异常

windows - 直接访问 Windows 后台处理程序中列出的 USB 打印机端口

c++ - 如何使 linux 命令行程序在 windows 中运行?

c++ - boost::array 不在 VS 2005 上编译