Fix type coercion from empty string pointer to 0

This commit is contained in:
drmortalwombat 2023-08-08 17:33:47 +02:00
parent b7630450f1
commit 07969d1fa6
3 changed files with 58 additions and 35 deletions

View File

@ -32,6 +32,8 @@ string::string(const string & s)
}
string::string(const char * s)
{
if (s)
{
char l = sstrlen(s);
if (l)
@ -43,6 +45,9 @@ string::string(const char * s)
else
cstr = nullptr;
}
else
cstr = nullptr;
}
string::string(const char * s, char size)
{
@ -102,6 +107,8 @@ string & string::operator=(const string & s)
string & string::operator=(const char * s)
{
free(cstr);
if (s)
{
char l = sstrlen(s);
if (l)
{
@ -111,6 +118,9 @@ string & string::operator=(const char * s)
}
else
cstr = nullptr;
}
else
cstr = nullptr;
return *this;
}
@ -140,6 +150,8 @@ string & string::operator+=(const string & s)
}
string & string::operator+=(const char * s)
{
if (s)
{
char sl = sstrlen(s);
if (sl)
@ -161,6 +173,7 @@ string & string::operator+=(const char * s)
smemcpy(cstr + 1, s, sl + 1);
}
}
}
return *this;
}
@ -225,6 +238,8 @@ string string::operator+(const string & s) const
string string::operator+(const char * s) const
{
if (cstr)
{
if (s)
{
char sl = sstrlen(s);
if (sl)
@ -238,6 +253,9 @@ string string::operator+(const char * s) const
else
return *this;
}
else
return *this;
}
else
return string(s);
}

View File

@ -16736,7 +16736,7 @@ void InterCodeProcedure::Close(void)
{
GrowingTypeArray tstack(IT_NONE);
CheckFunc = !strcmp(mIdent->mString, "MenuItem::+MenuItem");
CheckFunc = !strcmp(mIdent->mString, "main");
mEntryBlock = mBlocks[0];

View File

@ -150,6 +150,11 @@ InterCodeGenerator::ExValue InterCodeGenerator::CoerceType(InterCodeProcedure* p
v.mTemp = cins->mDst.mTemp;
v.mType = type;
}
else if (type->mType == DT_TYPE_POINTER && v.mType->mType == DT_TYPE_ARRAY)
{
v.mType = type;
return v;
}
else if (v.mType->mSize < type->mSize)
{
if (v.mType->mSize == 1 && type->mSize == 2)