From: cpp_novice on
{ Note: cross-posed to comp.lang.java.programmer. -mod/vdv }

Typically, languages do not allow an object to be constructed more
then once. Would allowing (re) construction cause a security failure,
perhaps indirectly, because of assumptions made by existing code bases?

[For instance, it is possible that an object may have file buffers open
and multiple constructor invocations may cause undesired behavior.]


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Ulrich Eckhardt on
cpp_novice(a)yahoo.com wrote:
> Typically, languages do not allow an object to be constructed more
> then once. Would allowing (re) construction cause a security failure,
> perhaps indirectly, because of assumptions made by existing code bases?
>
> [For instance, it is possible that an object may have file buffers open
> and multiple constructor invocations may cause undesired behavior.]

If the definition of 'construction' is to turn raw memory (with random
content) into a meaningful content, that operation might allocate resources
and store handles to said resources in the newly-created object. If you
repeat that, the former content is lost forever and the resources can't be
released anymore.

That said, in C++ at least, it is possible to create an object at a certain
memory location and destroy it explicitly. Using those two, you could
destroy an object and create a new one in the same piece of memory, and
there is nothing insecure or illegal about it.

However, if I give you a reference to a constant object, and you destroy it
and create another object in place, I would be very unhappy because that
would mean messing with my internal data. Also, this technique, while
theoretically sound, is rather unexpected so I would carefully document its
use.

Uli


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Frederick Gotham on

> Would allowing (re) construction cause a security failure,
> perhaps indirectly, because of assumptions made by existing code bases?


#include <new>

int main()
{
ClassType obj; /* Construction */

::new(&obj) ClassType; /* Re-construction */
}


Probably a bad idea, as it could result in the leakage of resources.

As for a securiy failure -- that depends entirely on the implementation of
the class. If the class contains a member which represents the access codes
for cruise missiles, then you might have a problem.

--

Frederick Gotham

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Matthias Hofmann on
"Ulrich Eckhardt" <eckhardt(a)satorlaser.com> schrieb im Newsbeitrag
news:ncvep3-nun.ln1(a)satorlaser.homedns.org...
> > cpp_novice(a)yahoo.com wrote:

> > However, if I give you a reference to a constant object, and you
destroy
it
> > and create another object in place, I would be very unhappy because
that
> > would mean messing with my internal data. Also, this technique, while
> > theoretically sound, is rather unexpected so I would carefully document
its
> > use.

Is it at all legal to explicitly call a destructor on a const object? The
standard says that delete can be called on pointers to const objects, but I
found no such rule for explicit destructor calls.

--
Matthias Hofmann
Anvil-Soft, CEO
http://www.anvil-soft.com - The Creators of Toilet Tycoon
http://www.anvil-soft.de - Die Macher des Klomanagers



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Gerhard Menzl on
Matthias Hofmann wrote:

> Is it at all legal to explicitly call a destructor on a const object?
> The standard says that delete can be called on pointers to const
> objects, but I found no such rule for explicit destructor calls.

12.4/2: "A destuctor can be invoked for a const, volatile or const
volatile object. [...] const and volatile semantics (7.1.5.1) are not
applied on an object under destruction. Such sematnics stop being into
effect once the destructor for the moste derived object (1.8) starts."


--
Gerhard Menzl

#dogma int main ()

Humans may reply by replacing the thermal post part of my e-mail address
with "kapsch" and the top level domain part with "net".

{Please review your sig. I've removed the "exclusive use" disclaimer.
The link to posting guidelines is below. -mod}


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

 |  Next  |  Last
Pages: 1 2
Prev: Union's
Next: How to learn the C++ way?