Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

project working in DEBUG mode but in RELEASE i get an error 1

Status
Not open for further replies.

stream2000

Programmer
Aug 17, 2002
6
US
I'm currently working on a project and i have some problems.
I made my own file type (a simple text file) and the problem appears when I'm trying to load a file. In DEBUG mode it works smoothly but in RELEASE mode I get an error.

This is the sequence :
______________________________________________

void CWallpaperDlg::OnFileLoad()
{


SetCurrentDirectory(m_strCurrDir);

CFileDialog dlg(TRUE);
dlg.m_ofn.lpstrFilter = "Image List Files (*.wps)\0*.WPS\00";
dlg.m_ofn.lpstrTitle = "Open Image List";
if (dlg.DoModal() == IDOK)
{

OnClear();
CFile File;
CFileException fileException;

int iOctetiCititi;
int i;

char szCitit[100] ;
char szFileName2[] = "";
strcpy(szFileName2 , dlg.GetFileName());
char szListFile[300];
for(i=0;i<300;i++)
{
szListFile='0';
}


File.Open(szFileName2 , CFile::modeRead , &fileException);

iOctetiCititi = 1;

int iContor=0;

while (iOctetiCititi > 0 )
{
iOctetiCititi = File.Read(szCitit, 1);


if ((szCitit[0] != 13) && (szCitit[0] != 10))
{
szListFile[iContor] = szCitit[0];
iContor++;

}
if (szCitit[0] == 13)
{
//strcat(szListFile,&quot;\0\0&quot;);
m_cListControl.InsertString( -1, szListFile);
//Curatare
for(i=0;i<iContor;i++)
{
szListFile=0;
}
iContor = 0;
}

}

File.Close();
}

}
_______________________________________________________
 
Here are the lines I would verify

SetCurrentDirectory(m_strCurrDir);// check the path

File.Open(szFileName2 , CFile::modeRead , &fileException);
// check on return value from &quot;Open&quot;

m_cListControl.InsertString( -1, szListFile);
// verify string IS REALLY null terminated. I dont see it that way.

Remove the for loop and try this

memset(szListFile,0,300);

instead of setting it to '0' which is teh ascii character zero and NOT ascii value zero.

I this this is the root of your problem. memory is initialized differently in debug and release depending on settings, 3rd party software, debugging tools etc...

See if this gets you anywhere

Matt
 
Additionally:
1. char szFileName2[] = &quot;&quot;; - has the length 0, and when You try to copy on this place:
strcpy(szFileName2 , dlg.GetFileName());
it does not work.
2. Sometimes File.Close(); gives an error in release mode, in debug all is ok - try to remove this line, CFile closes itself in destructor.
 
I think the main problem is here

char szFileName2[] = &quot;&quot;;

change to:

char szFileName2[4096];

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top