cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Erase memory for ProMdlName

Highlighted
Regular Member

Erase memory for ProMdlName

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.

Tags (2)
3 REPLIES 3
Highlighted

Re: Erase memory for ProMdlName

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

 

Highlighted

Re: Erase memory for ProMdlName

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

Highlighted

Re: Erase memory for ProMdlName

You should init a char string

 

DwgName[0] = '\0';

 

before using.

Announcements