Changeset - r27443:1150c64644d0
[Not reviewed]
master
0 2 0
Loïc Guilloux - 17 months ago 2023-05-27 16:09:21
glx22@users.noreply.github.com
Fix: Check max member count in squirrel classes (#10883)

Manual cherry-pick from https://github.com/albertodemichelis/squirrel/commit/23a0620658714b996d20da3d4dd1a0dcf9b0bd98
2 files changed with 4 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/3rdparty/squirrel/squirrel/sqclass.cpp
Show inline comments
 
@@ -56,24 +56,27 @@ SQClass::~SQClass()
 
}
 

	
 
bool SQClass::NewSlot(SQSharedState *ss,const SQObjectPtr &key,const SQObjectPtr &val,bool bstatic)
 
{
 
	SQObjectPtr temp;
 
	if(_locked)
 
		return false; //the class already has an instance so cannot be modified
 
	if(_members->Get(key,temp) && _isfield(temp)) //overrides the default value
 
	{
 
		_defaultvalues[_member_idx(temp)].val = val;
 
		return true;
 
	}
 
	if (_members->CountUsed() >= MEMBER_MAX_COUNT) {
 
		return false;
 
	}
 
	if(type(val) == OT_CLOSURE || type(val) == OT_NATIVECLOSURE || bstatic) {
 
		SQInteger mmidx;
 
		if((type(val) == OT_CLOSURE || type(val) == OT_NATIVECLOSURE) &&
 
			(mmidx = ss->GetMetaMethodIdxByName(key)) != -1) {
 
			_metamethods[mmidx] = val;
 
		}
 
		else {
 
			if(type(temp) == OT_NULL) {
 
				SQClassMember m;
 
				m.val = val;
 
				_members->NewSlot(key,SQObjectPtr(_make_method_idx(_methods.size())));
 
				_methods.push_back(m);
src/3rdparty/squirrel/squirrel/sqclass.h
Show inline comments
 
@@ -10,24 +10,25 @@ struct SQClassMember {
 
		val = o.val;
 
		attrs = o.attrs;
 
	}
 
	SQClassMember& operator=(SQClassMember &o) = delete;
 
	SQObjectPtr val;
 
	SQObjectPtr attrs;
 
};
 

	
 
typedef sqvector<SQClassMember> SQClassMemberVec;
 

	
 
#define MEMBER_TYPE_METHOD 0x01000000
 
#define MEMBER_TYPE_FIELD 0x02000000
 
#define MEMBER_MAX_COUNT 0x00FFFFFF
 

	
 
#define _ismethod(o) (_integer(o)&MEMBER_TYPE_METHOD)
 
#define _isfield(o) (_integer(o)&MEMBER_TYPE_FIELD)
 
#define _make_method_idx(i) ((SQInteger)(MEMBER_TYPE_METHOD|i))
 
#define _make_field_idx(i) ((SQInteger)(MEMBER_TYPE_FIELD|i))
 
#define _member_type(o) (_integer(o)&0xFF000000)
 
#define _member_idx(o) (_integer(o)&0x00FFFFFF)
 

	
 
struct SQClass : public CHAINABLE_OBJ
 
{
 
	SQClass(SQSharedState *ss,SQClass *base);
 
public:
0 comments (0 inline, 0 general)