A real gem.
-
Here's a gem I found in some C++ legacy Windows code I am starting to have to maintain:
if (hWnd ? hWnd == pWndAppts->m\_hWnd : pWndAppts) pWndAppts->DeleteSelected(); else if(hWnd ? hWnd == pWndNotes->m\_hWnd : pWndNotes) pWndNotes->DeleteSelected();
pWndNotes and pWndAppts are class pointers (the exact specifics are unimportant). hWnd is, well, an HWND. Note how nothing checks to be sure pWndNotes or pWndAppts are not NULL (until it is too late). :doh: Someone obviously thought they were very clever. :sigh:
-
Here's a gem I found in some C++ legacy Windows code I am starting to have to maintain:
if (hWnd ? hWnd == pWndAppts->m\_hWnd : pWndAppts) pWndAppts->DeleteSelected(); else if(hWnd ? hWnd == pWndNotes->m\_hWnd : pWndNotes) pWndNotes->DeleteSelected();
pWndNotes and pWndAppts are class pointers (the exact specifics are unimportant). hWnd is, well, an HWND. Note how nothing checks to be sure pWndNotes or pWndAppts are not NULL (until it is too late). :doh: Someone obviously thought they were very clever. :sigh:
Yuck.
Tom Delany wrote:
Someone obviously thought they were very clever.
Maybe they were some intern trying to be a show off?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Here's a gem I found in some C++ legacy Windows code I am starting to have to maintain:
if (hWnd ? hWnd == pWndAppts->m\_hWnd : pWndAppts) pWndAppts->DeleteSelected(); else if(hWnd ? hWnd == pWndNotes->m\_hWnd : pWndNotes) pWndNotes->DeleteSelected();
pWndNotes and pWndAppts are class pointers (the exact specifics are unimportant). hWnd is, well, an HWND. Note how nothing checks to be sure pWndNotes or pWndAppts are not NULL (until it is too late). :doh: Someone obviously thought they were very clever. :sigh:
Tom Delany wrote:
Note how nothing checks to be sure pWndNotes or pWndAppts are not NULL (until it is too late)
Without knowing the code, their could be the situation that pWndNotes or pWndAppts cannot be NULL if hWnd is not NULL. The converse is not true, hence the extra check.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
Tom Delany wrote:
Note how nothing checks to be sure pWndNotes or pWndAppts are not NULL (until it is too late)
Without knowing the code, their could be the situation that pWndNotes or pWndAppts cannot be NULL if hWnd is not NULL. The converse is not true, hence the extra check.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)That might be possible. I still have not gotten familiar enough with the code myself to say for sure, yet. I still think it would not have killed them to use a few more lines of code and written it a bit less obtusely. :mad:
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated. There are 10 kinds of people in the world: People who know binary and people who don't.
-
That might be possible. I still have not gotten familiar enough with the code myself to say for sure, yet. I still think it would not have killed them to use a few more lines of code and written it a bit less obtusely. :mad:
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated. There are 10 kinds of people in the world: People who know binary and people who don't.