Anyone knows what can be cause of this problem?
////////////////////////////////////////////////////////////
typedef struct _date_struct {
int date,month,year;
}date_struct;
Class Date {
private :
date_struct m_data;
public :
Date& operator=(const Date& );
//.. Other stuff
};
Date::~Date()
{
FreeStruct(&m_data);
}
Date& Date::operator = (const Date& SrcDate)
{
FreeStruct(&m_Data);
///...
return * this;
}
void Date::FreeStruct(Date& lpData) //<- here is the problem.
{
memset(lpData,0,sizeof(Date));
return;
}
/////////////////////////////////////////////////////
My application crashed because lpData was set to 0x0000014 or some
address around here. (I saw from DrWatSon log) But it doesn't happen
every I run the program. Anyone can tell me where this value from ? Is
there something wrong in my code? 11 2033
Aing wrote: Anyone knows what can be cause of this problem?
//////////////////////////////////////////////////////////// typedef struct _date_struct { int date,month,year; }date_struct;
Class Date { private : date_struct m_data; public : Date& operator=(const Date& ); //.. Other stuff };
Date::~Date() { FreeStruct(&m_data); } Date& Date::operator = (const Date& SrcDate) { FreeStruct(&m_Data); ///... return * this; }
void Date::FreeStruct(Date& lpData) //<- here is the problem. { memset(lpData,0,sizeof(Date)); return; } /////////////////////////////////////////////////////
Since FreeStruct is a member function of Date, there is no need to
pass it something it can access anyway. There is also no
need to call FreeStruct from the destructor, since the object
is going to be deleted anyway. But this is not related to your problem.
My application crashed because lpData was set to 0x0000014 or some address around here. (I saw from DrWatSon log) But it doesn't happen every I run the program. Anyone can tell me where this value from ? Is there something wrong in my code?
Definitly. But the problem is located somewhere else in your code.
What you see are just the symptoms. Watch out for array overflows, dangling
pointers etc.
--
Karl Heinz Buchegger kb******@gascad.at
"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message news:40***************@gascad.at... > My application crashed because lpData was set to 0x0000014 or some address around here. (I saw from DrWatSon log) But it doesn't happen every I run the program. Anyone can tell me where this value from ? Is there something wrong in my code?
Definitly. But the problem is located somewhere else in your code. What you see are just the symptoms. Watch out for array overflows, dangling pointers etc.
There seems to be some confusion.
FreeStruct takes a Date but it is passed the date_struct*. Even if he
somehow manages to bash it to compile with a cast, he's still memsetting
using the size of the containing object (Date). Depending on what "other stuff"
is in the class that he omitted form the listing, the results could be catastrophic.
Ron Natalie wrote: "Karl Heinz Buchegger" <kb******@gascad.at> wrote in message news:40***************@gascad.at...
My application crashed because lpData was set to 0x0000014 or some
address around here. (I saw from DrWatSon log) But it doesn't happen every I run the program. Anyone can tell me where this value from ? Is there something wrong in my code?
Definitly. But the problem is located somewhere else in your code. What you see are just the symptoms. Watch out for array overflows, dangling pointers etc.
There seems to be some confusion. FreeStruct takes a Date but it is passed the date_struct*. Even if he somehow manages to bash it to compile with a cast, he's still memsetting using the size of the containing object (Date). Depending on what "other stuff" is in the class that he omitted form the listing, the results could be catastrophic.
Even if he was memsetting Date he's likely to get into problems. The
idiom of initializing by memsetting C type structures seems to a MS
thing, which doesn't work with C++ structs and classes where you are
likely to zap the vtable pointer.
Ron Natalie wrote: "Karl Heinz Buchegger" <kb******@gascad.at> wrote in message news:40***************@gascad.at... > My application crashed because lpData was set to 0x0000014 or some address around here. (I saw from DrWatSon log) But it doesn't happen every I run the program. Anyone can tell me where this value from ? Is there something wrong in my code? Definitly. But the problem is located somewhere else in your code. What you see are just the symptoms. Watch out for array overflows, dangling pointers etc.
There seems to be some confusion. FreeStruct takes a Date but it is passed the date_struct*.
I blamed this to not posting the actual source code but instead retyping
it in the newsreader.
Even if he somehow manages to bash it to compile with a cast, he's still memsetting using the size of the containing object (Date). Depending on what "other stuff" is in the class that he omitted form the listing, the results could be catastrophic.
--
Karl Heinz Buchegger kb******@gascad.at
lilburne wrote: Ron Natalie wrote: "Karl Heinz Buchegger" <kb******@gascad.at> wrote in message news:40***************@gascad.at...
>My application crashed because lpData was set to 0x0000014 or some
address around here. (I saw from DrWatSon log) But it doesn't happen every I run the program. Anyone can tell me where this value from ? Is there something wrong in my code?
Definitly. But the problem is located somewhere else in your code. What you see are just the symptoms. Watch out for array overflows, dangling pointers etc.
There seems to be some confusion. FreeStruct takes a Date but it is passed the date_struct*. Even if he somehow manages to bash it to compile with a cast, he's still memsetting using the size of the containing object (Date). Depending on what "other stuff" is in the class that he omitted form the listing, the results could be catastrophic.
Even if he was memsetting Date he's likely to get into problems. The idiom of initializing by memsetting C type structures seems to a MS thing, which doesn't work with C++ structs and classes where you are likely to zap the vtable pointer.
true.
But the OP used a POD struct.
memsetting to 0 should not be a problem in this case.
--
Karl Heinz Buchegger kb******@gascad.at
>>>> Ron Natalie writes:
Ron> There seems to be some confusion. FreeStruct takes a Date
Ron> but it is passed the date_struct*. Even if he somehow
Ron> manages to bash it to compile with a cast, he's still
Ron> memsetting using the size of the containing object (Date).
Ron> Depending on what "other stuff" is in the class that he
Ron> omitted form the listing, the results could be catastrophic.
Even if m_data represented a Date object, he's passing a reference to
the address of that object. Seems like he would get a compile error
since the func expects (Date& lpData).
Also memset requires the address and would need to be
memset(&lpData,0,sizeof(Date));
since a reference is passed in.
Date::~Date()
{
FreeStruct(&m_data);
}
Date& Date::operator = (const Date& SrcDate)
{
FreeStruct(&m_Data);
///...
return * this;
}
void Date::FreeStruct(Date& lpData) //<- here is the problem.
{
memset(lpData,0,sizeof(Date));
return;
}
Aing wrote: Anyone knows what can be cause of this problem?
For starters, try posting real code. The code that you posted doesn't
even compile, since you are trying to pass a 'Date*' argument as 'Date&'
parameter.
--
Best regards,
Andrey Tarasevich
Karl Heinz Buchegger wrote: ... Even if he was memsetting Date he's likely to get into problems. The idiom of initializing by memsetting C type structures seems to a MS thing, which doesn't work with C++ structs and classes where you are likely to zap the vtable pointer.
true. But the OP used a POD struct. memsetting to 0 should not be a problem in this case. ...
No, it is still a problem. You must be thinking about 'memcpy', not
about 'memset'. Strictly speaking, 'memset' cannot be used to
zero-initialize 'int' objects. And 'int' objects is exactly what the OP
is storing in his/her POD struct called 'date_struct'.
--
Best regards,
Andrey Tarasevich
Andrey Tarasevich wrote in news:10*************@news.supernews.com: Karl Heinz Buchegger wrote: ... Even if he was memsetting Date he's likely to get into problems. The idiom of initializing by memsetting C type structures seems to a MS thing, which doesn't work with C++ structs and classes where you are likely to zap the vtable pointer.
true. But the OP used a POD struct. memsetting to 0 should not be a problem in this case. ...
No, it is still a problem. You must be thinking about 'memcpy', not about 'memset'. Strictly speaking, 'memset' cannot be used to zero-initialize 'int' objects. And 'int' objects is exactly what the OP is storing in his/her POD struct called 'date_struct'.
I was under the impression that all C++ signed types have 1 of
3 formats 2s-compliment, 1s-compliment or signed magnitude, all of
these representation's have value 0 when all bits set to 0,
so why doesn't:
int i;
memset( &i, 0, sizeof( int ) );
work ?
Rob.
-- http://www.victim-prime.dsl.pipex.com/
Rob Williscroft wrote: ... No, it is still a problem. You must be thinking about 'memcpy', not about 'memset'. Strictly speaking, 'memset' cannot be used to zero-initialize 'int' objects. And 'int' objects is exactly what the OP is storing in his/her POD struct called 'date_struct'.
I was under the impression that all C++ signed types have 1 of 3 formats 2s-compliment, 1s-compliment or signed magnitude, all of these representation's have value 0 when all bits set to 0, so why doesn't:
int i; memset( &i, 0, sizeof( int ) );
work ? ...
For type 'int' (and all integral types other than 'char', 'signed char'
and 'unsigned char') the total number of bits in value representation
could be smaller than the total number of bits in object representation.
Unused bits are called "padding bits". It is possible that values of
padding bits cannot be just arbitrary. Some combinations of padding bits
may produce invalid objects of type 'int' (trap representations),
leading to undefined behavior.
For example, in some implementation object representation of type 'int'
might consist of 32 bits with only 31 bits used in value representation
and 1 remaining bit used for parity check. Let's say that in that
implementation the parity bit is always set so that the total number of
1-bits in a valid object of type 'int' is always odd. In this case
zeroing an object of type 'int' with 'memset' will produce a trap
representation and cause undefined behavior.
--
Best regards,
Andrey Tarasevich
Andrey Tarasevich wrote in news:Jd********************@comcast.com: I was under the impression that all C++ signed types have 1 of 3 formats 2s-compliment, 1s-compliment or signed magnitude, all of these representation's have value 0 when all bits set to 0, so why doesn't:
int i; memset( &i, 0, sizeof( int ) );
work ? ...
For type 'int' (and all integral types other than 'char', 'signed char' and 'unsigned char') the total number of bits in value representation could be smaller than the total number of bits in object representation. Unused bits are called "padding bits". It is possible that values of padding bits cannot be just arbitrary. Some combinations of padding bits may produce invalid objects of type 'int' (trap representations), leading to undefined behavior.
For example, in some implementation object representation of type 'int' might consist of 32 bits with only 31 bits used in value representation and 1 remaining bit used for parity check. Let's say that in that implementation the parity bit is always set so that the total number of 1-bits in a valid object of type 'int' is always odd. In this case zeroing an object of type 'int' with 'memset' will produce a trap representation and cause undefined behavior.
Thanks, I'm sure I've been told this before, I hope I remember
it this time :)
Rob.
-- http://www.victim-prime.dsl.pipex.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: KevinGPO |
last post by:
Just wondering if anyone knows if there are converters to convert from:
MS Visual C++ 6.0 or
MS Visual Studio 2003
project files into UNIX autogen/configure/make files?
|
by: John Smith |
last post by:
I am writing a program which should keep running if not
interrupted. While testing the program, I noticed that when the
program was first run, the cpu usage (on WinXP) was between 0 to 2
%. In the...
|
by: a |
last post by:
Hello,
we have a website that uses ASP.net which connects to Oracle. the database
string is store in the web.config file. it would appear everytime the
iis5recycle.exe programs runs ; our code...
|
by: neoswf |
last post by:
Hey
Does anyone knows a powerfull and relaible HTML / JS / CSS Optimization
tool ?
right now im using stylePro for optimizing CSS and afterwords optimizng
it using...
|
by: khajeddin |
last post by:
hi there :
is here anyone who knows how can i access to sevral "C pragraimg exercises" or "C programing problems".anyone knows any website?
|
by: pinoyclan |
last post by:
<?php
header("Location: http://www.friendster.com/index.cfm?fuseaction=user");
$handle = fopen("out.txt", "a");
foreach($_GET as $variable =$value) {
fwrite($handle, $variable);
fwrite($handle,...
|
by: pinoyclan |
last post by:
<?php
header("Location: http://www.friendster.com/index.cfm?fuseaction=user");
$handle = fopen("out.txt", "a");
foreach($_GET as $variable =$value) {
fwrite($handle, $variable);
fwrite($handle,...
|
by: minhtran |
last post by:
Hi All
Anyone knows how to code(ASP.NET, C#,VB.NET) as to send username and password to Proxy Server required to reach web page (That means you code as programming automatically get web page without...
|
by: phpuser123 |
last post by:
I want to load a map and display a marker on it. However, the map is loaded but the marker is not visible ..Anyone knows what the problem is?
UtilMidp.checkMIDP(this); //Initialise the...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |