View previous topic :: View next topic |
Author |
Message |
DietmarSiepmann
Joined: 03 Jun 2013 Posts: 279
|
Posted: Thu Apr 04, 2019 4:17 pm Post subject: Problem realloc for scc 64 bit |
|
|
Hello,
when porting a ftn95 application from 32 bit to 64 bit we make use of C/CPP calls malloc and realloc. The following code may be used to compile/link a 32 bit and a 64 bit executable using Salford`s scc compiler. The 32 bit executable works ok, however, for the 64 bit executable the realloc call returns the null pointer, when it should not.
Code: |
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main() {
int chunk_size=16;
char* pChunk,*pChunk1;
pChunk=(char*)malloc(chunk_size);
printf("pChunk=0x%x\n",pChunk);
pChunk1=(char*)realloc(pChunk,chunk_size);
printf("pChunk1=0x%x\n",pChunk1);
strcpy(pChunk1,"123456781234567812345678");
printf("*pChunk1=%s\n",pChunk1);
return 0;
}
|
Output of 32 bit exe:
Code: |
pChunk=0x3805970
pChunk1=0x3805958
*pChunk1=123456781234567812345678
|
Output of 64 bit exe:
Code: |
pChunk=0x1d5bd0
pChunk1=0x0
|
A a consequence of realloc returning the NULL pointer the 64 bit executable crashes with an access violation.
Version information of scc:
[Silverfrost SCC/WIN32 Ver 4.20 Copyright (c) Silverfrost Ltd 2018]
Regards,
Dietmar |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7931 Location: Salford, UK
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7931 Location: Salford, UK
|
Posted: Fri Apr 05, 2019 7:27 am Post subject: |
|
|
Dietmar
In the rush of things I did not check this before replying.
It does not work for me so I will investigate further. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7931 Location: Salford, UK
|
|
Back to top |
|
|
DietmarSiepmann
Joined: 03 Jun 2013 Posts: 279
|
Posted: Fri Apr 05, 2019 10:57 am Post subject: |
|
|
Paul,
thanks for the quick response and solution. The test sample runs as expected now (the pointer returned by the 64 bit exe is now different from NULL
By the way I forgot to increase the chunk_size in my test sample before the realloc call
Regards,
Dietmar |
|
Back to top |
|
|
|