Fix constness of reference parameter of standard copy assignment operator

This commit is contained in:
drmortalwombat 2025-05-24 17:49:51 +02:00
parent 81e5321bfc
commit 0af17f0f40
3 changed files with 94 additions and 1 deletions

View File

@ -667,6 +667,97 @@ void * calloc(int num, int size)
return p;
}
void * realloc(void * ptr, unsigned size)
{
if (ptr)
{
#ifdef HEAPCHECK
Heap * pheap = (Heap *)((char *)ptr - 6);
Heap * eheap = pheap->next;
unsigned psize = (char *)eheap - (char *)pheap;
void * nptr = malloc(size);
memcpy(nptr, ptr, psize - 6);
free(ptr);
return nptr;
#else
unsigned nsize = (size + 5) & ~3;
// Get heap info
Heap * pheap = (Heap *)((char *)ptr - 2);
Heap * eheap = pheap->next;
unsigned psize = (char *)eheap - (char *)pheap;
Heap * h = HeapNode.next;
Heap * hp = &HeapNode;
while (h && h < pheap)
{
hp = h;
h = h->next;
}
if (nsize <= psize)
{
// check if we should free some memory
if (nsize + sizeof(HeapNode) < psize)
{
Heap * nheap = (Heap *)((char *)pheap + nsize);
pheap->next = nheap;
if (h == eheap)
{
nheap->end = h->end;
nheap->next = h->next;
}
else
{
nheap->end = eheap;
nheap->next = h;
}
hp->next = nheap;
}
return ptr;
}
else if (h == eheap)
{
// Free space after this
// Check if enough space if extending
unsigned xsize = (char *)h->end - (char *)pheap;
if (xsize >= nsize)
{
if (xsize > nsize + sizeof(HeapNode))
{
Heap * nheap = (Heap *)((char *)pheap + nsize);
pheap->next = nheap;
nheap->end = h->end;
nheap->next = h->next;
hp->next = nheap;
}
else
{
pheap->next = h->end;
hp->next = h->next;
}
return ptr;
}
}
void * nptr = malloc(size);
memcpy(nptr, ptr, psize - 2);
free(ptr);
return nptr;
#endif
}
else
return malloc(size);
}
static unsigned seed = 31232;
unsigned int rand(void)

View File

@ -45,6 +45,8 @@ void free(void * ptr);
void * calloc(int num, int size);
void * realloc(void * ptr, unsigned size);
unsigned heapfree(void);
unsigned int rand(void);

View File

@ -3458,7 +3458,7 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
adec->mOffset = 0;
adec->mBase = new Declaration(mScanner->mLocation, DT_TYPE_REFERENCE);
adec->mBase->mSize = 2;
adec->mBase->mBase = pthis->mBase;
adec->mBase->mBase = pthis->mBase->ToConstType();
adec->mBase->mFlags |= DTF_CONST | DTF_DEFINED;
adec->mSize = adec->mBase->mSize;
adec->mIdent = adec->mQualIdent = Ident::Unique("_");