C ++ GCC4.4警告:数组下标是以上数组界限 [英] C++ GCC4.4 warning: array subscript is above array bounds

查看:1488
本文介绍了C ++ GCC4.4警告:数组下标是以上数组界限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


  

在成员函数'无效控制台:打印(常量标准::字符串&安培;)


  
  

警告:数组下标是以上数组边界


这里的code:

 无效控制台:打印(常量标准::字符串&安培; STR){
    标准::字符串行(STR);
    如果(newLine.size()> MAX_LINE_LENGTH){
    SF :: UINT32 stringsize的= newLine.size();
    对于(SF :: UINT32 insertPos = MAX_LINE_LENGTH;
    insertPos< stringsize的; insertPos + = MAX_LINE_LENGTH){
    newLine.insert(insertPos,\\ n);
    }
    }    StringList的标记;
    提高::分(标记符,换行符,提振:: is_any_of(\\ n));    对于(StringList的:迭代它= tokens.begin();
    !它= tokens.end();它++){
    addLine(*它);
    }
    }

任何想法?


这是正在做的优化...

此外,它似乎是这条线,这是造成的:

 的boost ::分(标记符,换行符,提振:: is_any_of(\\ n));


是啊,我发现它,它是提升)的说法:: is_any_of(通过在一个字符串()构造函数警告消失包裹吧,谢谢大家的帮助:)

 的boost ::分(标记符,换行符,提振:: is_any_of(字符串(\\ n)));


解决方案

得到了同样的错误。作为一种变通方法我换成

  is_any_of()

  is_from_range('','')

其中可能也有稍微更有效。

I recently upgraded to GCC 4.4 (MinGW TDM build) and now the follow code produces these warning:

In member function 'void Console::print(const std::string&)':

warning: array subscript is above array bounds

Here's the code:

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 );
    	}
    }

Any ideas?


It is the optimizations that are doing it...

Also it appears to be this line which is causing it:

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


Ah yes, I found it, it is the argument for boost::is_any_of(), by wrapping it in a string() constructor the warning goes away, thank you all for your help :)

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

解决方案

Got the same error. As a workaround I replaced

is_any_of(" ")

with

is_from_range(' ', ' ')

which might also be slightly more efficient.

这篇关于C ++ GCC4.4警告:数组下标是以上数组界限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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