C++ GCC4.4警告:数组下标在数组边界之上

Ada*_*dam 8 c++ gcc boost tdm-mingw

我最近升级到GCC 4.4(MinGW TDM版本),现在跟随代码产生这些警告:

在成员函数'void Console :: print(const std :: string&)'中:

警告:数组下标在数组边界之上

这是代码:

void Console::print( const std::string& str ) {
        std::string newLine( str );
        if( newLine.size() > MAX_LINE_LENGTH ) {
            sf::Uint32 stringSize = newLine.size();
            for( sf::Uint32 insertPos = MAX_LINE_LENGTH;
                    insertPos < stringSize; insertPos += MAX_LINE_LENGTH ) {
                newLine.insert( insertPos, "\n" );
            }
        }

        StringList tokens;
        boost::split( tokens, newLine, boost::is_any_of("\n") );

        for( StringList::iterator it = tokens.begin();
                it != tokens.end(); ++it ) {
            addLine( *it );
        }
    }
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?


这是优化正在做...

它似乎是这条线导致它:

boost::split( tokens, newLine, boost::is_any_of("\n") );
Run Code Online (Sandbox Code Playgroud)

是啊,我发现它,它是boost :: is_any_of()的参数,通过将它包装在string()构造函数中警告消失,谢谢大家的帮助:)

boost::split( tokens, newLine, boost::is_any_of( string( "\n" ) ) );
Run Code Online (Sandbox Code Playgroud)

Pat*_*hly 3

遇到同样的错误。作为解决方法,我更换了

is_any_of(" ")
Run Code Online (Sandbox Code Playgroud)

is_from_range(' ', ' ')
Run Code Online (Sandbox Code Playgroud)

这也可能会稍微更有效率。