Skip to main content
1-Visitor
October 16, 2019
Question

Erase memory for ProMdlName

  • October 16, 2019
  • 2 replies
  • 1782 views

Hi all,

 

I use code following code to create a Directory using toolkit

 

err = ProFileMdlnameParse(SelPath00, OutPutPath, MdlName, Ext, rev);
ProWstringToString(DwgName, MdlName);
mkdir(strcat("C:\\temp\\", DwgName))

 

When i run the application second time, the DwgName is getting appended.

(i.e first time DwgName is 1234, second time it becomes 12341234)

Kindly suggest.

2 replies

14-Alexandrite
October 17, 2019

Hi, probably  due to the improper use of strcat.

Function strcat has first parameter the pointer to resulting array (this pointer is also returned), second param is string to append.

For the first time you append string to the end of array which begin at some address, second time append next string to this array and so on ... (string array will overlap, exception occurred).

 

Try to refill the result string (strcpy), at least, e.g.:

 

char dir [PRO_PATH_SIZE];

strcpy(dir, "C:\\temp\\");

strcat(dir, DwgName);

 

Btw: You should not use strcat, try something like ProTKSnprintf

 

PZ

 

15-Moonstone
December 4, 2019

At least strcat_s(dir, PRO_PATH_SIZE, DwgName); so you get a crash at "out of allocated memory" and not write over other variables/allocated space inside your memory.

 

Br,

Eike

18-Opal
December 4, 2019

You should init a char string

 

DwgName[0] = '\0';

 

before using.