<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>IsBadXxxPtr should really be called CrashProgramRandomly</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx</link><description>Masking a bug just creates a different, harder-to-find, bug.</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>Complexity  &amp;laquo; Computing Life</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx#3479998</link><pubDate>Sat, 23 Jun 2007 15:02:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3479998</guid><dc:creator>Complexity  « Computing Life</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://computinglife.wordpress.com/2007/06/23/how-do-you-chose-your-apis/"&gt;http://computinglife.wordpress.com/2007/06/23/how-do-you-chose-your-apis/&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=3479998" width="1" height="1"&gt;</description></item><item><title>re: IsBadReadPtr, IsBadWritePtr APIが禁止に - Windows Vista</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx#1057696</link><pubDate>Sat, 11 Nov 2006 12:08:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1057696</guid><dc:creator>社本＠ワック Blog</dc:creator><description>&lt;p&gt;re: IsBadReadPtr, IsBadWritePtr APIが禁止に - Windows Vista&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1057696" width="1" height="1"&gt;</description></item><item><title>re: IsBadXxxPtr should really be called CrashProgramRandomly</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx#790627</link><pubDate>Wed, 04 Oct 2006 19:17:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:790627</guid><dc:creator>Dave Harris</dc:creator><description>&lt;p&gt;&amp;gt; The documentation for the IsBadXxxPtr&lt;/p&gt;
&lt;p&gt;&amp;gt; functions presents the technical reasons why&lt;/p&gt;
&lt;p&gt;Not really. It says, &amp;quot;Dereferencing potentially invalid pointers can disable stack expansion in other threads&amp;quot; but it doesn't say that IsBadXxxPtr dereferences the pointer. In fact I'd read it as saying the opposite: that you should use IsBadXxxPtr in order to avoid the stack expansion problem, because IsBadXxxPtr tells you whether the dereference would succeed without actually dereferencing it, by accessing the memory manager hardware directly. That's what I'd expect, and the documentation doesn't disillusion me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=790627" width="1" height="1"&gt;</description></item><item><title>re: IsBadXxxPtr should really be called CrashProgramRandomly</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx#790119</link><pubDate>Wed, 04 Oct 2006 19:02:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:790119</guid><dc:creator>Dave Harris</dc:creator><description>&lt;p&gt;The assertion won't catch all bad pointers even without race conditions. For example, some might point to memory which has been free()d (hence shouldn't be used) but which is still part of the crt heap (hence owned by the app as far as IsBadXxxPtr is concerned). It can still be useful to catch at least some errors, eg of the 0x00000008 form I mentioned earlier, or due to uninitialised pointer variables etc.&lt;/p&gt;
&lt;p&gt;The false positives are a more serious issue. The real problem with IsBadXxxPtr for assert purposes is not that it has unwanted side effects on the (potentially random) memory page, but that it lies: it can return true for memory which can, in fact, be read or written to.&lt;/p&gt;
&lt;p&gt;However, this is unlikely. It's unlikely to happen with stack frames, because the memory should come from the stack frame of routine which is higher up the stack, and that memory ought to be committed by the time our assert is hit. So we're left with the people playing games with PAGE_NOACCESS. Don't use the assert if you want to play those games.&lt;/p&gt;
&lt;p&gt;Generally it would be better to just use the memory. The only times I'd even consider adding the assert are (a) as documentation; and (b) when the routine only used the memory some of the time, and I wanted the caller to make it available all of the time. The same applies to ASSERT( p != NULL ). Assertions for things which the hardware will detect anyway are often unnecessary clutter.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=790119" width="1" height="1"&gt;</description></item><item><title>re: IsBadXxxPtr should really be called CrashProgramRandomly</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx#785833</link><pubDate>Tue, 03 Oct 2006 16:02:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:785833</guid><dc:creator>BryanK</dc:creator><description>&lt;p&gt;Er, wait, the above comment makes no sense. &amp;nbsp;If you get a bad pointer in a release build, you'll just crash, same as if you never used IsBad*Ptr.&lt;/p&gt;
&lt;p&gt;So never mind. &amp;nbsp;(And sorry about the duplicate comment; it made sense to me at the time...)&lt;/p&gt;
&lt;p&gt;But I still don't see the point. &amp;nbsp;You won't necessarily catch all bad pointers (see the race condition), and you'll catch some pointers as bad that aren't actually.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=785833" width="1" height="1"&gt;</description></item><item><title>re: IsBadXxxPtr should really be called CrashProgramRandomly</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx#785828</link><pubDate>Tue, 03 Oct 2006 16:00:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:785828</guid><dc:creator>BryanK</dc:creator><description>&lt;p&gt;&amp;gt; from an IDE&lt;/p&gt;
&lt;p&gt;So you expect you'll *never* get an invalid pointer when your release build is running?&lt;/p&gt;
&lt;p&gt;This seems way too optimistic to me.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=785828" width="1" height="1"&gt;</description></item><item><title>re: IsBadXxxPtr should really be called CrashProgramRandomly</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx#785019</link><pubDate>Tue, 03 Oct 2006 14:57:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:785019</guid><dc:creator>Dave Harris</dc:creator><description>&lt;p&gt;BryanK wrote@&lt;/p&gt;
&lt;p&gt;&amp;gt; But the caller can't catch a failed assert&lt;/p&gt;
&lt;p&gt;&amp;gt; like they can catch an exception.&lt;/p&gt;
&lt;p&gt;They shouldn't be trying to catch it. They should let the program terminate.&lt;/p&gt;
&lt;p&gt;&amp;gt; All they get is a dialog &amp;quot;assertion failed:&lt;/p&gt;
&lt;p&gt;&amp;gt; IsBadReadPtr(x)&amp;quot;, which really doesn't help&lt;/p&gt;
&lt;p&gt;&amp;gt; narrow anything down.&lt;/p&gt;
&lt;p&gt;That depends on which assert you use and what your debugging tools are. Would it help if I wrote ASSERT instead of assert? With my IDE, an assertion failure gives the option to halt the program at the offending line, with the stack and variables available for inspection. I can switch to other threads and inspect them, too.&lt;/p&gt;
&lt;p&gt;Remember we are talking about DEBUG builds, which normally means it is being run by a programmer from an IDE like Visual Studio. An end-user would be using a RELEASE build and not have the IsBadReadPtr check at all.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=785019" width="1" height="1"&gt;</description></item><item><title>re: IsBadXxxPtr should really be called CrashProgramRandomly</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx#784869</link><pubDate>Tue, 03 Oct 2006 14:17:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:784869</guid><dc:creator>Michiell</dc:creator><description>&lt;p&gt;I'm surprised that these functions can't be removed from the API. Just put an #if (!Vista) before them. Any program written for XP will not only continue to run, but can still be compiled. Only programs written or updated for Vista will be impacted.&lt;/p&gt;
&lt;p&gt;That's a good thing for Microsoft too; it improves applications build for Vista only, and thus is an upgrade reason for consumers. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=784869" width="1" height="1"&gt;</description></item><item><title>re: IsBadXxxPtr should really be called CrashProgramRandomly</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx#780149</link><pubDate>Mon, 02 Oct 2006 03:56:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:780149</guid><dc:creator>JimD</dc:creator><description>I agree with the arguments against using IsBadxxxPtr. It just always seemed like a good way to check pre-conditions.&lt;br&gt;&lt;br&gt;I see MFC 8 (Visual Studio 2005) changed the AfxIsValidAddress, AfxIsValidString to no longer make the IsBadReadPtr/IsBadWritePtr calls. They now simply check for a null pointer. No string length checks, etc.&lt;br&gt;&lt;br&gt;I haven't checked if the VS2003 SP1 made the same changes, but I guess I would expect that it did.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=780149" width="1" height="1"&gt;</description></item><item><title>re: IsBadXxxPtr should really be called CrashProgramRandomly</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx#779874</link><pubDate>Mon, 02 Oct 2006 00:08:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:779874</guid><dc:creator>Russell Davis</dc:creator><description>Raymond, I'm confused by this paragraph:
&lt;br&gt;
&lt;br&gt;"Swallowing the exception in IsBadXxxPtr means that the caller's exception handler doesn't get a chance to run, which means that your code rejected a pointer that would actually have been okay, if only you had let the exception handler do its thing."
&lt;br&gt;
&lt;br&gt;Think about that for a minute. Since the caller's exception handler has to run for the pointer to be valid INSIDE the callee, that means that the caller's exception handler must be set up to handle and stop the exception without the callee even knowing an exception was raised (which is indeed how guard page exceptions are handled). So exception swallowing is NOT the problem!
&lt;br&gt;
&lt;br&gt;As a couple other commenters have noted, the real problem is that these guard page handlers are tied to a specific thread. If you access the guard page on a different thread, the handler won't get called, and problems will arise.
&lt;br&gt;
&lt;br&gt;So it seems that in a single threaded situation (like the scenario mentioned in that paragraph), IsBadXxxPtr will not cause guard page problems.
&lt;br&gt;
&lt;br&gt;Am I missing something?&lt;BR&gt;&lt;BR&gt;&lt;DIV CLASS=post&gt;[&lt;I&gt;There are multiple problems with swallowing exceptions. I pointed out one of them (pointer swizzling); you pointed out another (stack guard pages). There is no conflict here. -Raymond&lt;/I&gt;]&lt;/DIV&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=779874" width="1" height="1"&gt;</description></item></channel></rss>