|
What do you mean by "It is giving breakpoint"? Do you mean that it is failing an ASSERT? If yes, where and what?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
It is showing corruption of heap.
|
|
|
|
|
So you created a static like this: mystatic = new CStatis; , and deleted it like this: delete mystatis; and you get something like "the heap around whatever has been corrupted"?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I have created member variable CStatic *m_myStatic ;,I am allocating memory like this m_myStatic = new CStatic[m_filecount];, and I am deleting in destructor.It is showing breakpoint is due to corruption of heap.
|
|
|
|
|
How are you deleting it ?
like this : delete [] m_myStatic;
This signature was proudly tested on animals.
|
|
|
|
|
I see, well, you need to delete an array -as Maximilien already pointed out- like this: delete []m_myStatic; . Otherwise, heap corruption can be caused by indexing out of your array, so you try to write items in the array which are not in the array at all, for example:
int *int_array = new int[5];
int_array[10] = 4;
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
This is not related at all. How you use an array has nothing to do with how you destroy it.
|
|
|
|
|
He said he gets "corruption of heap", that -as far as i know- can be caused by what i said there. The question wasn't specifically "how to delete an array".
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Code-o-mat wrote: He said he gets "corruption of heap"...
When he deletes, not accesses.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Correct me when i am wrong but -at least in debug- when you allocate an array using new, the system will allocate somewhat more bytes than explicitly needed by your array and will place some special information infront and after your block. When you delete the array the system will check these special values infront and after the array and if it does not find what it expects it will complain about it because this probably means you wrote to memory you should not have written to. True, the example there was a bad one, i should have wrote int_array[5] = 4; instead of int_array[10] = 4; , because 10 is WAY after the lest element of the array...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
How unbelievable it might seem, there are even more ways to corrupt a piece of memory than there are unspecific questions on this forum
|
|
|
|
|
Lol! My bad! I was reading your 'Otherwise' as 'if you don't delete scalar you will get memory corruption'.
|
|
|
|
|
Guess i should express myself more clearly, sorry...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Hi
We have a MFC Application in which we decide to perform a task based on the mouse click position.
We have a formula that converts this x and y value info into a index number,which we use to retrieve info
Now our customer have given us a crash dump in which CPoint x and y value has 5882 and 1150 which are very huge. Due to which the index generated is very high and since this index does not exists we get a crash(segmentation fault)
In our test we never get such high x and y value.
Can anyone explain the reason for this high x and y values?
Does resolution impact the x and y values?
thanks in advance
from
nayeem khan
|
|
|
|
|
nayeemkhan wrote: Can anyone explain the reason for this high x and y values?
nayeemkhan wrote: We have a formula that converts this x and y value info into a index number,which we use to retrieve info
I've got no idea...but I can suggest a way in which you can stop the crashes. Either validate your input data (you can find the screen extents easily enough - it makes sense that the mouse position should be on-screen?) or validate the index you've generated from the mouse position.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi Stuart Dootson
Thanks for the reply
I have already coded the validation of x and y (which u suggested)
But i was wondering how can a resolution of screen can be such huge 5800x1150.
I am also investigating with respect to data limits of x and y.
Can we get a boo/tutorial which explains exactly how CPoint structure gets the x and y values?
from
nayeem khan
|
|
|
|
|
nayeemkhan wrote: I have already coded the validation of x and y (which u suggested)
I would suggest that validation of the index would be rather more useful
nayeemkhan wrote: Can we get a boo/tutorial which explains exactly how CPoint structure gets the x and y values?
Where does the CPoint come from? Is it from a Windows message?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
nayeemkhan wrote: Now our customer have given us a crash dump in which CPoint x and y value has 5882 and 1150 which are very huge.
Can you post the code where you retrieve those values ?
|
|
|
|
|
Hi
Below is the part of code which gets the x and y values and converts it to a index variable called ListClick
I have commented the code where ever necessary
void CHierDispWnd::OnLButtonDown( UINT , CPoint Point )
{
int ListClick;
long MemClick;
int GapX,GapY;
GapX = m_pStdProps->m_iGapX;
GapY = m_pStdProps->m_iGapY;
int mem_wd,mem_ht;
mem_wd = m_pStdProps->m_iMemWidth;
mem_ht = m_pStdProps->m_iMemHeight;
SetFocus();
if ((Point.x < CXSCROLLBTN) || (Point.y < GapY))
return;
ListClick = (Point.x - CXSCROLLBTN) / (mem_wd + GapX);
if (!pMiddle->ListValid( ListClick))
return;
}
|
|
|
|
|
Theoretically you can have very large numbers here, since the point is relative the window (this->m_hWnd). You can have windows a lot larger than the resolution of your screen. But I think that is only possible if you set the window size from your code. I don't know a way for a user to do that unless you explicitly allow it in your program. Do you do that?
|
|
|
|
|
nayeemkhan wrote: if (!pMiddle->ListValid( ListClick))//CRASHES IN THIS FUNC...LISTCLICK is 41,which does not //exists
So verify that it exists before trying to use it. This does not fix the problem of point.x equaling 5882 but it does keep your app from crashing.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
One possibility could be that your user has a virtual desktop (see Wiki[^], check the "Scrolling desktops" part) which can be any size i guess depending on what software the user might be using for it...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Perhaps your client has dual monitors, and has them set up to act like a single desktop window. That would make the X values double what you might expect while the Y values would be "normal".
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
But wouldn't this would still require one monitor to have an x-axis of (about) 2941?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
To create a secured MS Access database programmatically using MFC I followed the procedure described at http://www.litwindow.com/Knowhow/HowTo/howto_create_secure_access_dat.html[^]. I have incorporated the code in one of my functions. However, while granting privileges to the newly created group exception is thrown and I am not able to create the database. The function in which I am using the code is as below.
void CSecuredAccessDlg::OnBnClickedOk()
{
if(m_fileName.IsEmpty())
{
MessageBox("No file selected!",NULL,MB_ICONERROR);
return;
}
CString strConfig,sSql;
CString strAccessDriver;
CDatabase database;
strAccessDriver="Microsoft Access Driver (*.mdb)";
if(_access("my workgroup.mdw",0)==0)
unlink("my workgroup.mdw");
if(_access(m_fileName,0)==0)
unlink(m_fileName);
strConfig.Format("CREATE_SYSDB=\"my workgroup.mdw\"\0\0");
SQLConfigDataSource(NULL, ODBC_ADD_DSN, strAccessDriver,strConfig);
strConfig.Empty();
strConfig.Format("CREATE_DB=\"%s\"\0\0",m_fileName);
SQLConfigDataSource(NULL, ODBC_ADD_DSN, strAccessDriver,strConfig);
strConfig.Empty();
TRY
{
strConfig.Format("DRIVER={%s};DSN='';READONLY=FALSE;"
"CREATE_DB=\"%s\";DBQ=%s;SystemDB=%s;UID=admin;"
"ExtendedAnsiSQL=1",strAccessDriver,m_fileName,m_fileName,
"my workgroup.mdw");
if(database.OpenEx(strConfig,CDatabase::noOdbcDialog))
{
sSql.Format("CREATE GROUP %s %s","Administrators","1234ABC");
database.ExecuteSQL(sSql);
sSql.Empty();
sSql.Format("CREATE USER %s \"%s\" %s","Pani","","1234DEF");
database.ExecuteSQL(sSql);
sSql.Empty();
sSql.Format("ADD USER %s TO %s","Pani","Administrators");
database.ExecuteSQL(sSql);
sSql.Empty();
sSql.Format("ADD USER %s TO %s","Pani","admins");
database.ExecuteSQL(sSql);
database.Close();
unlink(m_fileName);
strConfig.Empty();
strConfig.Format("CREATE_DB=\"%s\"\0SystemDB=my workgroup.mdw"
"\0UID=Pani\0\0",m_fileName);
SQLConfigDataSource(NULL, ODBC_ADD_DSN, strAccessDriver,strConfig);
strConfig.Format("DRIVER={%s};DSN='';READONLY=FALSE;"
"CREATE_DB=\"%s\";DBQ=%s;SystemDB=%s;UID=Pani;ExtendedAnsiSQL=1",
strAccessDriver,m_fileName,m_fileName,"my workgroup.mdw");
if(database.OpenEx(strConfig))
{
sSql.Format("GRANT ALL PRIVILEGES ON DATABASE TO Administrators");
database.ExecuteSQL(sSql);
sSql.Format("REVOKE ALL PRIVILEGES ON DATABASE FROM admin");
database.ExecuteSQL(sSql);
sSql.Format("REVOKE ALL PRIVILEGES ON DATABASE FROM admins");
database.ExecuteSQL(sSql);
sSql.Format("REVOKE ALL PRIVILEGES ON DATABASE FROM users");
database.ExecuteSQL(sSql);
sSql.Format("ALTER USER Pani PASSWORD %s \"%s\"","pani123","");
database.ExecuteSQL(sSql);
FillData(&database);
database.Close();
}
}
}
CATCH(CDBException, e)
{
if(database.IsOpen())
database.Close();
MessageBox(e->m_strError,NULL,MB_ICONERROR);
return;
}
END_CATCH
}
Can anyone provide suggestions for correcting the code?
Thanks in advance.
Pani68
modified on Thursday, April 2, 2009 3:32 AM
|
|
|
|