Home » Developing U++ » U++ TheIDE and Library: Releases and ChangeLogs » Hopefully fixed "Writes to freed blocks" bug in ide - and warning (quiz)
|
|
|
|
|
|
Re: Hopefully fixed "Writes to freed blocks" bug in ide - and warning (quiz) [message #12287 is a reply to message #12286] |
Tue, 23 October 2007 18:08 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
mdelfede wrote on Tue, 23 October 2007 11:50 |
luzr wrote on Tue, 23 October 2007 17:41 |
Nope. But it returns a reference. However, .At invalidates references to Vector.... So if the left side of statement is evaluated before the right side, you have "free block overwrite"...
Mirek
|
Uhmmm... what is the reason of invalidating the ref ? At() isn't the same as operator [], for array ?
|
No, it can resize the array if you use i >= GetCount.
Quote: |
BTW, I was thinkin' about it yesterday.... why did you use the pick_ stuff instead of something like a pimpl object with copy-on-write ? It's not feasible ?
|
IMO/IME, shared ownership is the root of evil At least in C++.
Mirek
[Updated on: Tue, 23 October 2007 18:08] Report message to a moderator
|
|
|
Re: Hopefully fixed "Writes to freed blocks" bug in ide - and warning (quiz) [message #12290 is a reply to message #12287] |
Tue, 23 October 2007 18:20 |
mdelfede
Messages: 1307 Registered: September 2007
|
Ultimate Contributor |
|
|
luzr wrote on Tue, 23 October 2007 18:08 |
No, it can resize the array if you use i >= GetCount.
|
Ah, ok... I wouldn't ever use it like that, it's the easy way of producing bugs.... Much better an explicit Realloc() or something like that. BTW resizing the array makes the assumption that elements have a default constructor, too.
Quote: |
IMO/IME, shared ownership is the root of evil At least in C++.
|
well, if you share ownership (like I've suggested) you MUST avoid any kind of pointers, but if it's well done can be rock solid.
Of course, if you use reference counted stuffs and than you take address of if, you can be sure about having bugs
I must say that reference counted stuffs are usually small in size, so you can pass them by value with few overhead.
I did something like that some time ago and it was nice to use.
Ciao
Max
|
|
|
Re: Hopefully fixed "Writes to freed blocks" bug in ide - and warning (quiz) [message #12293 is a reply to message #12290] |
Tue, 23 October 2007 19:45 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
mdelfede wrote on Tue, 23 October 2007 12:20 |
luzr wrote on Tue, 23 October 2007 18:08 |
No, it can resize the array if you use i >= GetCount.
|
Ah, ok... I wouldn't ever use it like that, it's the easy way of producing bugs....
|
Well, I think At is extremely effective way how to solve many problems. And similar issue existis even in the plain C
a[i++] = a[i];
it is simply something you have to care about...
Quote: |
I must say that reference counted stuffs are usually small in size, so you can pass them by value with few overhead.
I did something like that some time ago and it was nice to use.
|
Well, yes, I think that is the "official" C++/boost path... If you like that, U++ pick_ must sound alien to you
Mirek
|
|
|
Re: Hopefully fixed "Writes to freed blocks" bug in ide - and warning (quiz) [message #12297 is a reply to message #12293] |
Tue, 23 October 2007 21:47 |
mdelfede
Messages: 1307 Registered: September 2007
|
Ultimate Contributor |
|
|
luzr wrote on Tue, 23 October 2007 19:45 |
Well, I think At is extremely effective way how to solve many problems. And similar issue existis even in the plain C
a[i++] = a[i];
it is simply something you have to care about...
|
Well, in your example, you can see that you're doing it wrong.
In theide bug, you can't.... or, at least, you can't if you don't know upp vector internals, what's normally the matter.
Usually people see Vector<> as a blackbox, they don't know (at least, I didn't know) about invalid references caused by At().
OTOH, people that program in C++ usually know that A[i++]=A[i] is a nonsense.
Quote: |
Well, yes, I think that is the "official" C++/boost path... If you like that, U++ pick_ must sound alien to you
|
Uhm... I don't know Boost++ in depth, but I don't think PIMPL+reference counting is their base path.
I know that reference counting + pointers is an hassle, but together with PIMPL and WITHOUT use of pointers can be quite good. That said, I don't like too much Boost++, I find it well written but old style coding. I did write my own Array class in past because of that.
BTW, I still think that c++ standard is missing many useful constructs, one of the most useful ot them is the 'property' one, which borland introduced as a language extension in their compilers.
An object-oriented language without properties is an empty wine glass, I think
Just an example of it :
class C
{
private:
int iVal;
void set_iVal(int _i) { i = _iVal; }
int get_iVal(void) { return iVal; }
public:
__property i = { read = getIval, write = setIval };
};
C c ;
c.i = 5; // calls set_Ival(5)
int a = c.i; // calls a = get_Ival()
That's what I call 'clean object-oriented language'.
Ciao
Max
|
|
|
Goto Forum:
Current Time: Wed May 08 06:14:38 CEST 2024
Total time taken to generate the page: 0.01674 seconds
|