Showing tag results for Code

Feb 17, 2004
Post comments count0
Post likes count2

GetDialogBaseUnits is a crock

Raymond Chen
Raymond Chen

Each dialog can have different base units, so it's meaningless to have a global converter.

Code
Feb 10, 2004
Post comments count0
Post likes count0

Answer to exercise: Pointer to member function cast

Raymond Chen
Raymond Chen

Yesterday's exercise asked you to predict and explain the codegen for the following fragment: Well, the codegen might go something like this: Let's use one of our fancy pictures: Just for fun, I swapped the order of Base1 and Base2. There is no requirement in the standard about the order in which storage is allocated for base classes, so ...

Code
Feb 9, 2004
Post comments count0
Post likes count2

Pointers to member functions are very strange animals

Raymond Chen
Raymond Chen

Pointers to member functions are very strange animals. Warning: The discussion that follows is specific to the way pointers to member functions are implemented by the Microsoft Visual C++ compiler. Other compilers may do things differently. Well, okay, if you only use single inheritance, then pointers to member functions are just a pointer to ...

Code
Feb 4, 2004
Post comments count0
Post likes count0

Answers to exercises – mismatching new/delete

Raymond Chen
Raymond Chen

Answers to yesterday's exercises: What happens if you allocate with scalar "new" and free with vector "delete[]"? The scalar "new" will allocate a single object with no hidden counter. The vector "delete[]" will look for the hidden counter, which isn't there, so it will either crash (accessing nonexistent memory) or grab a random number and a...

Code
Feb 3, 2004
Post comments count0
Post likes count0

Mismatching scalar and vector new and delete

Raymond Chen
Raymond Chen

In a previous entry I alluded to the problems that can occur if you mismatch scalar "new" with vector "delete[]" or vice versa. There is a nice description of C++ memory management in C++ Gotchas: Avoiding Common Problems in Coding and Design on www.informit.com, and I encourage you to read at least the section titled Failure to Distinguish Sca...

Code
Jan 29, 2004
Post comments count0
Post likes count1

Integer overflow in the new[] operator

Raymond Chen
Raymond Chen

Integer overflows are becoming a new security attack vector. Mike Howard's article discusses some of the ways you can protect yourself against integer overflow attacks. One attack vector he neglects to mention is integer overflow in the new[] operator. This operator performs an implicit multiplication that is unchecked: If you study the code g...

Code
Jan 28, 2004
Post comments count0
Post likes count2

Another reason not to do anything scary in your DllMain: Inadvertent deadlock

Raymond Chen
Raymond Chen

Your DllMain function runs inside the loader lock, one of the few times the OS lets you run code while one of its internal locks is held. This means that you must be extra careful not to violate a lock hierarchy in your DllMain; otherwise, you are asking for a deadlock. (You do have a lock hierarchy in your DLL, right?) The loader lock is tak...

Code