Silverfrost Forums

Welcome to our forums

Problem realloc for scc 64 bit

4 Apr 2019 3:17 #23431

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.

#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:

pChunk=0x3805970
pChunk1=0x3805958
*pChunk1=123456781234567812345678

Output of 64 bit exe:

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

4 Apr 2019 4:22 #23432

This has already been fixed and a new set of DLLs is available here for testing...

https://www.dropbox.com/s/tnx0fokexiug77i/newDLLs33.zip?dl=0

The function is in salflibc64.dll.

5 Apr 2019 6:27 #23437

Dietmar

In the rush of things I did not check this before replying.

It does not work for me so I will investigate further.

5 Apr 2019 8:43 #23438

This has now been fixed in this set of DLLs...

https://www.dropbox.com/s/2fiv6pwnsdq3e50/newDLLs34.zip?dl=0

5 Apr 2019 9:57 #23440

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

Please login to reply.