From 07969d1fa66c0426bb38d025cb2a71234fc71f62 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Tue, 8 Aug 2023 17:33:47 +0200 Subject: [PATCH] Fix type coercion from empty string pointer to 0 --- include/opp/string.cpp | 86 ++++++++++++++++++++-------------- oscar64/InterCode.cpp | 2 +- oscar64/InterCodeGenerator.cpp | 5 ++ 3 files changed, 58 insertions(+), 35 deletions(-) diff --git a/include/opp/string.cpp b/include/opp/string.cpp index 4973fda..1b86951 100644 --- a/include/opp/string.cpp +++ b/include/opp/string.cpp @@ -33,12 +33,17 @@ string::string(const string & s) string::string(const char * s) { - char l = sstrlen(s); - if (l) - { - cstr = malloc(char(l + 2)); - cstr[0] = l; - smemcpy(cstr + 1, s, l + 1); + if (s) + { + char l = sstrlen(s); + if (l) + { + cstr = malloc(char(l + 2)); + cstr[0] = l; + smemcpy(cstr + 1, s, l + 1); + } + else + cstr = nullptr; } else cstr = nullptr; @@ -102,12 +107,17 @@ string & string::operator=(const string & s) string & string::operator=(const char * s) { free(cstr); - char l = sstrlen(s); - if (l) + if (s) { - cstr = malloc(char(l + 2)); - cstr[0] = l; - smemcpy(cstr + 1, s, l + 1); + char l = sstrlen(s); + if (l) + { + cstr = malloc(char(l + 2)); + cstr[0] = l; + smemcpy(cstr + 1, s, l + 1); + } + else + cstr = nullptr; } else cstr = nullptr; @@ -141,24 +151,27 @@ string & string::operator+=(const string & s) string & string::operator+=(const char * s) { - char sl = sstrlen(s); - if (sl) + if (s) { - if (cstr) + char sl = sstrlen(s); + if (sl) { - char l = sl + cstr[0]; - char * c = malloc(char(l + 2)); - c[0] = l; - smemcpy(c + 1, cstr + 1, cstr[0]); - smemcpy(c + 1 + cstr[0], s, sl + 1); - free(cstr); - cstr = c; - } - else - { - cstr = malloc(char(sl + 2)); - cstr[0] = sl; - smemcpy(cstr + 1, s, sl + 1); + if (cstr) + { + char l = sl + cstr[0]; + char * c = malloc(char(l + 2)); + c[0] = l; + smemcpy(c + 1, cstr + 1, cstr[0]); + smemcpy(c + 1 + cstr[0], s, sl + 1); + free(cstr); + cstr = c; + } + else + { + cstr = malloc(char(sl + 2)); + cstr[0] = sl; + smemcpy(cstr + 1, s, sl + 1); + } } } return *this; @@ -226,14 +239,19 @@ string string::operator+(const char * s) const { if (cstr) { - char sl = sstrlen(s); - if (sl) + if (s) { - char l = cstr[0] + sl; - char * p = malloc(char(l + 2)); - smemcpy(p + 1, cstr + 1, cstr[0]); - smemcpy(p + 1 + cstr[0], s, sl); - return string(l, p); + char sl = sstrlen(s); + if (sl) + { + char l = cstr[0] + sl; + char * p = malloc(char(l + 2)); + smemcpy(p + 1, cstr + 1, cstr[0]); + smemcpy(p + 1 + cstr[0], s, sl); + return string(l, p); + } + else + return *this; } else return *this; diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 06b6ed9..df97f20 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -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]; diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index 7663feb..0612f0e 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -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)