-assignment of ord to string index made valid #1072

This commit is contained in:
Juan Linietsky 2015-01-02 13:17:46 -03:00
parent 2e08e11120
commit 28daf19744

View file

@ -922,20 +922,30 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
case REAL: { return; } break; case REAL: { return; } break;
case STRING: { case STRING: {
if (p_value.type!=Variant::STRING)
if (p_index.type!=Variant::INT && p_index.type!=Variant::REAL)
return; return;
if (p_index.get_type()==Variant::INT || p_index.get_type()==Variant::REAL) {
//string index
int idx=p_index; int idx=p_index;
String *str=reinterpret_cast<String*>(_data._mem); String *str=reinterpret_cast<String*>(_data._mem);
if (idx >=0 && idx<str->length()) { if (idx <0 || idx>=str->length())
String chr = p_value; return;
String chr;
if (p_value.type==Variant::INT || p_value.type==Variant::REAL) {
chr = String::chr(p_value);
} else if (p_value.type==Variant::STRING) {
chr = p_value;
} else {
return;
}
*str = str->substr(0,idx-1)+chr+str->substr(idx+1,str->length()); *str = str->substr(0,idx-1)+chr+str->substr(idx+1,str->length());
valid=true; valid=true;
return; return;
}
}
} break; } break;
case VECTOR2: { case VECTOR2: {