J
Jerith
Hey guys,
I am having a problem with stack corruption in my code (it tells me
that the stack around the variable 'code' is corrupted). I think I what
is happening is that in both instances of the sscanf that I am using,
'code' is being given more than it can handle. So my question is is
there some way I can replace sscanf with something that won't corrupt
the stack around 'code'?
Thanks in advance,
JC
void CSEPAC_Logic_BuilderDlg::OnButtonSave()
{
CFile f;
CString txt;
CString newfile;
int i;
unsigned short code;
FILE *fp;
char strFilter[] = { "SLB Files (*.slb)|*.slb|All Files (*.*)|*.*||"
};
CFileDialog
FlDlg(FALSE,".slb",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,strFilter);
if( FlDlg.DoModal() == IDOK )
{
f.Open(FlDlg.GetFileName(), CFile::modeCreate |
CFile::modeWrite );
newfile = f.GetFileName();
newfile.TrimRight(".slb");
newfile = newfile + ".bin";
fp = fopen(newfile, "wb");
CArchive ar(&f, CArchive::store);
ar << m_name << m_comment;
for (i = 1; i < 2001; i++)
{
m_ocl.SetRow(i); /* set the row we are operating on */
m_ocl.SetCol(INST); /* extract the ascii instruction string */
txt = m_ocl.GetText();
if (txt == "" ) break; /* last instruction ? */
else ar << txt;
m_ocl.SetCol(REG); /* extract the ascii register to operate
on */
txt = m_ocl.GetText();
ar << txt;
m_ocl.SetCol(OPCODE); /* extract the ascii-hex opcode */
txt = m_ocl.GetText();
ar << txt;
sscanf(txt,"%x",&code);
switch (code)
{
case 20: code = 0x7e7e; break;
default: code = swap_bytes(code);
case 0: break;
}
fwrite((const void*)&code, 1, sizeof(code), fp);
m_ocl.SetCol(OPERAND); /* extract the ascii-hex operand */
txt = m_ocl.GetText();
ar << txt;
if (txt != "") sscanf(txt, "%x", &code);
else code = 0x0000;
code = swap_bytes(code);
fwrite((const void*)&code, 1, sizeof(code), fp);
}
fclose(fp);
ar.Close();
MessageBox("IOMap File '" + newfile + "' has been created.");
}
else
return;
fclose(fp);
}
I am having a problem with stack corruption in my code (it tells me
that the stack around the variable 'code' is corrupted). I think I what
is happening is that in both instances of the sscanf that I am using,
'code' is being given more than it can handle. So my question is is
there some way I can replace sscanf with something that won't corrupt
the stack around 'code'?
Thanks in advance,
JC
void CSEPAC_Logic_BuilderDlg::OnButtonSave()
{
CFile f;
CString txt;
CString newfile;
int i;
unsigned short code;
FILE *fp;
char strFilter[] = { "SLB Files (*.slb)|*.slb|All Files (*.*)|*.*||"
};
CFileDialog
FlDlg(FALSE,".slb",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,strFilter);
if( FlDlg.DoModal() == IDOK )
{
f.Open(FlDlg.GetFileName(), CFile::modeCreate |
CFile::modeWrite );
newfile = f.GetFileName();
newfile.TrimRight(".slb");
newfile = newfile + ".bin";
fp = fopen(newfile, "wb");
CArchive ar(&f, CArchive::store);
ar << m_name << m_comment;
for (i = 1; i < 2001; i++)
{
m_ocl.SetRow(i); /* set the row we are operating on */
m_ocl.SetCol(INST); /* extract the ascii instruction string */
txt = m_ocl.GetText();
if (txt == "" ) break; /* last instruction ? */
else ar << txt;
m_ocl.SetCol(REG); /* extract the ascii register to operate
on */
txt = m_ocl.GetText();
ar << txt;
m_ocl.SetCol(OPCODE); /* extract the ascii-hex opcode */
txt = m_ocl.GetText();
ar << txt;
sscanf(txt,"%x",&code);
switch (code)
{
case 20: code = 0x7e7e; break;
default: code = swap_bytes(code);
case 0: break;
}
fwrite((const void*)&code, 1, sizeof(code), fp);
m_ocl.SetCol(OPERAND); /* extract the ascii-hex operand */
txt = m_ocl.GetText();
ar << txt;
if (txt != "") sscanf(txt, "%x", &code);
else code = 0x0000;
code = swap_bytes(code);
fwrite((const void*)&code, 1, sizeof(code), fp);
}
fclose(fp);
ar.Close();
MessageBox("IOMap File '" + newfile + "' has been created.");
}
else
return;
fclose(fp);
}