<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>SafeInt Discussions Rss Feed</title><link>http://www.codeplex.com/SafeInt/Thread/List.aspx</link><description>SafeInt Discussions Rss Description</description><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;blockquote style="border: 0.1em solid #cccccc; font-style: italic; margin: 0.25em 1em 0pt; padding: 0pt 0.25em;"&gt;&lt;strong&gt;Timothy003 wrote:&lt;/strong&gt;&lt;br /&gt;
&lt;p&gt;Boost has really smart people in its community, and sets ultra-high standards.&amp;nbsp; Libraries are peer-reviewed too, so you'd get a lot of good feedback on your code.&amp;nbsp; For example, I grabbed the latest SafeInt3.hpp, opened it up,&amp;nbsp;and immediately saw this:&lt;/p&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;#&lt;span style="color: blue;"&gt;if&lt;/span&gt; !defined NULL
#define NULL ((&lt;span style="color: blue;"&gt;void&lt;/span&gt;*)0)
#endif
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: green;"&gt;// These two may not be defined, either&lt;/span&gt;
#&lt;span style="color: blue;"&gt;if&lt;/span&gt; !defined uintptr_t
#define uintptr_t size_t
#endif

#&lt;span style="color: blue;"&gt;if&lt;/span&gt; !defined intptr_t
#define intptr_t ptrdiff_t
#endif
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: green;"&gt;// Might need this for gcc and older Microsoft compilers&lt;/span&gt;
#&lt;span style="color: blue;"&gt;if&lt;/span&gt; !defined &lt;span style="color: blue;"&gt;nullptr&lt;/span&gt;
#define &lt;span style="color: blue;"&gt;nullptr&lt;/span&gt; NULL
#endif
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Code like that is evil.&amp;nbsp; The folks at Boost would surely&amp;nbsp;let you know about it, and you'll learn modern C++ programming paradigms, improving the quality of your code.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;# Boost has really smart people in its community, and sets ultra-high standards.&lt;br /&gt;I'm not sure about the ultra high standards.&lt;/p&gt;
&lt;p&gt;# Libraries are peer-reviewed too, so you'd get a lot of good feedback on your code&lt;br /&gt;That&amp;nbsp; Boost will accept anything and hope that someone will [eventually] spot an error is a detriment, not a feature. For example, it appears Boost accepted threads and rolled them out without rigorous review or acceptance testing. Distributions generally don't backport bug fixes, so downlevel users are stuck with defective code.&lt;/p&gt;
&lt;p&gt;On my cursory review, Boost::Threads did not meet production quality (I filed about 15 bugs against it). For example, ignoring return values from WaitForSingleObject and pthread_mutex_lock was egregious. Its something I would expect from a self-taught K&amp;amp;R coder. I don't think a CompSci freshman would make the same mistakes. And I don't want code like that in my code base.&lt;/p&gt;
&lt;p&gt;It also appears Boost does not audit the bug database. To date, none of the bugs have even been acknowledged.&lt;/p&gt;
&lt;p&gt;# Code like that is evil.&lt;br /&gt;Have a look at Boost::Test and its use of macros sometime...&lt;/p&gt;&lt;/div&gt;</description><author>noloader</author><pubDate>Sun, 25 Sep 2011 21:57:01 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110925095701P</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;blockquote style="border: 0.1em solid #cccccc; font-style: italic; margin: 0.25em 1em 0pt; padding: 0pt 0.25em;"&gt;&lt;strong&gt;Timothy003 wrote:&lt;/strong&gt;&lt;br /&gt;
&lt;blockquote style="padding: 0px 0.25em; font-style: italic; margin: 0.25em 1em 0px; border: 0.1em solid #cccccc;"&gt;&lt;strong&gt;noloader wrote:&lt;/strong&gt;&lt;br /&gt;
&lt;blockquote style="padding: 0pt 0.25em; font-style: italic; margin: 0.25em 1em 0pt; border: 0.1em solid #cccccc;"&gt;&lt;strong&gt;Timothy003 wrote:&lt;/strong&gt;&lt;br /&gt;
&lt;p&gt;.... In most cases, the overhead will be negligible.&amp;nbsp; Without solid profiling, I can't justify the security tradeoff.&amp;nbsp; But if you have proof that the vector has too much overhead, then of course you shouldn't use it.&amp;nbsp; Otherwise, it would be premature optimization.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Seriously? A program has to be correct before anything else.&lt;/p&gt;
&lt;p&gt;Out of curiosity, how can you be certain the attacker does not control the input?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;br /&gt; Are you implying that dcleblanc's&amp;nbsp;code is safer and more correct?&amp;nbsp; Other than relying on undefined behavior with the type punning, there's already a bug in it; it doesn't validate the packet's size.&amp;nbsp; With vector, iterator debugging will give you a better chance  of catching incorrect code.&lt;/p&gt;
&lt;p&gt;The two examples don't do the same things, anyway.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;# Are you implying that dcleblanc's&amp;nbsp;code is safer and more correct?&lt;br /&gt; Yes, I believe LeBlanc's SafeInt code is safer in general.&lt;/p&gt;
&lt;p&gt;If the time ever comes, I believe ignoring wrap and overflow will be grossly negligent. The industry enjoys software patents, it should also enjoy liability.&lt;/p&gt;
&lt;p&gt;# Other than relying on undefined behavior with the type punning...&lt;br /&gt; My bad, I was commenting in general, not in the particular examples.&lt;/p&gt;
&lt;p&gt;For what its worth, the Visual Studio compiler is more tolerant of punning. I think VS just does the right thing and gets the alignments right (with no warning).&lt;/p&gt;
&lt;p&gt;# With vector, iterator debugging will give you a better chance of catching incorrect code.&lt;br /&gt; I love debug builds and asserts (I'm a student of John Robbins), but this is a problem in practice. To convince yourself, install libboost via apt-get or yum and define _GLIBCXX_DEBUG (http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode.html). I recently  [incorreclty] filed a report against Boost::Regex (it was an ABI problem).&lt;/p&gt;
&lt;p&gt;I know I could have built the source from scratch. But Boost has broken the tried and true configure/make/install in favor of something else buried in a spaghetti of documentation. I could be wrong, but I had no joy in building on Solaris (a Boost bug report  was filed, no acknowledgement to date).&lt;/p&gt;
&lt;p&gt;Jeff&lt;/p&gt;&lt;/div&gt;</description><author>noloader</author><pubDate>Sun, 25 Sep 2011 20:33:23 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110925083323P</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;blockquote style="padding-bottom: 0px; font-style: italic; margin: 0.25em 1em 0px; padding-left: 0.25em; padding-right: 0.25em; padding-top: 0px; border: #ccc 0.1em solid;"&gt;&lt;strong&gt;noloader wrote:&lt;/strong&gt;&lt;br /&gt;
&lt;blockquote style="padding-bottom: 0pt; font-style: italic; margin: 0.25em 1em 0pt; padding-left: 0.25em; padding-right: 0.25em; padding-top: 0pt; border: #cccccc 0.1em solid;"&gt;&lt;strong&gt;Timothy003 wrote:&lt;/strong&gt;&lt;br /&gt;
&lt;p&gt;.... In most cases, the overhead will be negligible.&amp;nbsp; Without solid profiling, I can't justify the security tradeoff.&amp;nbsp; But if you have proof that the vector has too much overhead, then of course you shouldn't use it.&amp;nbsp; Otherwise, it would be premature optimization.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Seriously? A program has to be correct before anything else.&lt;/p&gt;
&lt;p&gt;Out of curiosity, how can you be certain the attacker does not control the input?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;br /&gt;Are you implying that dcleblanc's&amp;nbsp;code is safer and more correct?&amp;nbsp; Other than relying on undefined behavior with the type punning, there's already a bug in it; it doesn't validate the packet's size.&amp;nbsp; With vector, iterator debugging will give you a better chance of catching incorrect code.&lt;/p&gt;
&lt;p&gt;The two examples don't do the same things, anyway.&lt;/p&gt;&lt;/div&gt;</description><author>Timothy003</author><pubDate>Sat, 24 Sep 2011 20:44:51 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110924084451P</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;blockquote style="border: 0.1em solid #cccccc; font-style: italic; margin: 0.25em 1em 0pt; padding: 0pt 0.25em;"&gt;&lt;strong&gt;Timothy003 wrote:&lt;/strong&gt;&lt;br /&gt;
&lt;p&gt;.... In most cases, the overhead will be negligible.&amp;nbsp; Without solid profiling, I can't justify the security tradeoff.&amp;nbsp; But if you have proof that the vector has too much overhead, then of course you shouldn't  use it.&amp;nbsp; Otherwise, it would be premature optimization.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Seriously? A program has to be correct before anything else.&lt;/p&gt;
&lt;p&gt;Out of curiosity, how can you be certain the attacker does not control the input?&lt;/p&gt;&lt;/div&gt;</description><author>noloader</author><pubDate>Sat, 24 Sep 2011 20:28:56 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110924082856P</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;It really depends on the requirements of the application.&amp;nbsp; In most cases, the overhead will be negligible.&amp;nbsp; Without solid profiling, I can't justify the security tradeoff.&amp;nbsp; But if you have proof that the vector has too much overhead, then of course you shouldn't use it.&amp;nbsp; Otherwise, it would be premature optimization.&lt;/p&gt;
&lt;p&gt;There's a way to get the fixed-width types without the header by using limits.h instead, but practically only Boost needs that kind of portability.&lt;/p&gt;&lt;/div&gt;</description><author>Timothy003</author><pubDate>Thu, 11 Aug 2011 02:45:43 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110811024543A</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Heh - here's how you really do it:&lt;/p&gt;
&lt;p&gt;unsigned long GetHeaderLen(const char* pPacket, unsigned long cbPacket)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; ip* pIp = reinterpret_cast&amp;lt;ip*&amp;gt;(pPacket);&lt;br /&gt;&amp;nbsp;&amp;nbsp; if( ﻿pIp == NULL || pIp-&amp;gt;﻿ip_v != 4) return 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp; unsigned long len =&amp;nbsp;pIp-&amp;gt;ip_hl * 8; // int overflow not possible, ip_hl can be at most 15 - only 4 bits&lt;br /&gt;&amp;nbsp;&amp;nbsp; return len&amp;nbsp;&amp;gt; cbPacket || len &amp;lt; 20 ?&amp;nbsp;0 : len;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;Lots easier and no overhead. You _can_ do nearly anything using STL, the question is whether maybe plain old C might be a more efficient choice (and sometimes more readable)&lt;/p&gt;
&lt;p&gt;Usually Visual Studio fixes up line endings - have to look into that.&lt;/p&gt;
&lt;p&gt;The point about the header is why I try as much as possible to avoid depending on them (for this sort of project). Given some number of compilers that are supported on some number of platforms, the more headers, the more chance for headaches.&lt;/p&gt;&lt;/div&gt;</description><author>dcleblanc</author><pubDate>Thu, 11 Aug 2011 01:09:17 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110811010917A</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;This should work:&lt;/p&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;void&lt;/span&gt; handle_packet(vector&amp;lt;&lt;span style="color: blue;"&gt;char&lt;/span&gt;&amp;gt; packet)
{
    &lt;span style="color: green;"&gt;// determine length of IP header&lt;/span&gt;
    uint32_t word_1;
    packet.at(4 - 1);
    memcpy(&amp;amp;word_1, &amp;amp;packet[0], 4);
    word_1 = ntohl(word_1);
    &lt;span style="color: blue;"&gt;auto&lt;/span&gt; length = 4 * (SafeInt&amp;lt;uint32_t&amp;gt;(word_1) &amp;lt;&amp;lt; 24 &amp;gt;&amp;gt; 24 &amp;gt;&amp;gt; 4);
    &lt;span style="color: blue;"&gt;if&lt;/span&gt; (length &amp;lt; 20)
        &lt;span style="color: blue;"&gt;throw&lt;/span&gt; some_error();
    packet.at(length - 1);
    &lt;span style="color: green;"&gt;// get iterator to data section&lt;/span&gt;
    &lt;span style="color: blue;"&gt;auto&lt;/span&gt; data = packet.begin() + length;
    &lt;span style="color: blue;"&gt;if&lt;/span&gt; (data != packet.end())
    {
        &lt;span style="color: green;"&gt;// do stuff with data&lt;/span&gt;
    }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The only reason to use operator new[] that I can think of is optimization, though vector is so fast in VC10 that I can't see it happening much.&amp;nbsp;&amp;nbsp;I would store variable-length structs using malloc.&amp;nbsp; operator new[] seems inappropriate if I'm circumventing the type system anyway.&lt;/p&gt;
&lt;p&gt;I know it sucks giving up nullptr.&amp;nbsp; I love it myself.&amp;nbsp; NULL&amp;nbsp;was&amp;nbsp;a mistake&amp;nbsp;to me.&amp;nbsp; But I've tried shoehorning nullptr into my program when&amp;nbsp;GCC didn't have it, and it wasn't easy.&amp;nbsp; std::function needed an overload for nullptr_t, for example.&lt;/p&gt;
&lt;p&gt;stdint.h isn't available in VC9.&amp;nbsp; I wanted to see if you would add typedefs for an extra layer of portability, like:&lt;/p&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: green;"&gt;// assume we have &amp;lt;stdint.h&amp;gt; by default&lt;/span&gt;
#define SAFEINT_HAS_STDINT_H
&lt;span style="color: green;"&gt;// MSVC versions earlier than 10.0&lt;/span&gt;
#&lt;span style="color: blue;"&gt;if&lt;/span&gt; defined _MSC_VER &amp;amp;&amp;amp; _MSC_VER &amp;lt; 1600
#undef SAFEINT_HAS_STDINT_H
#endif  &lt;span style="color: green;"&gt;// defined _MSC_VER &amp;amp;&amp;amp; _MSC_VER &amp;lt; 1600&lt;/span&gt;

#ifdef SAFEINT_HAS_STDINT_H
#include &amp;lt;stdint.h&amp;gt;
#endif  &lt;span style="color: green;"&gt;// SAFEINT_HAS_STDINT_H&lt;/span&gt;

&lt;span style="color: blue;"&gt;namespace&lt;/span&gt; safeint
{
#ifdef SAFEINT_HAS_STDINT_H
    &lt;span style="color: blue;"&gt;using&lt;/span&gt; ::int8_t;
    &lt;span style="color: blue;"&gt;using&lt;/span&gt; ::uint8_t;
#elif defined _MSC_VER
    &lt;span style="color: blue;"&gt;typedef&lt;/span&gt; __int8 int8_t;
    &lt;span style="color: blue;"&gt;typedef&lt;/span&gt; &lt;span style="color: blue;"&gt;unsigned&lt;/span&gt; __int8 uint8_t;
#&lt;span style="color: blue;"&gt;else&lt;/span&gt;   &lt;span style="color: green;"&gt;// defined _MSC_VER&lt;/span&gt;
#error need fixed-width integer types
#endif  &lt;span style="color: green;"&gt;// defined _MSC_VER&lt;/span&gt;

    &lt;span style="color: blue;"&gt;template&lt;/span&gt;&amp;lt;&lt;span style="color: blue;"&gt;class&lt;/span&gt; Ty&amp;gt;
    &lt;span style="color: blue;"&gt;class&lt;/span&gt; safeint
    {
    &lt;span style="color: blue;"&gt;public&lt;/span&gt;:
        &lt;span style="color: blue;"&gt;operator&lt;/span&gt; int8_t() &lt;span style="color: blue;"&gt;const&lt;/span&gt;;

        &lt;span style="color: blue;"&gt;operator&lt;/span&gt; uint8_t() &lt;span style="color: blue;"&gt;const&lt;/span&gt;;
    }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;That's how I would do it.&lt;/p&gt;
&lt;p&gt;By the way, the line endings are inconsistent in 3.0.16.&lt;/p&gt;&lt;/div&gt;</description><author>Timothy003</author><pubDate>Wed, 10 Aug 2011 22:27:38 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110810102738P</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;I don't have time to pull up the headers to show a concrete&amp;nbsp;example, but an IP header is a variable-length structure that has a minimum of 20 bytes. So you have to calculate the offset to the TCP header, and you end up using pointer math to do so. I could allocate the bytes using a vector, but the only gain I'd get out of it would be to have it clean itself up, and I'd take a hit of some overhead in what's typically highly perf-sensitive code. If I can't realistically use iterators, then converting the vector to a raw pointer really doesn't gain me much in terms of safety.&lt;/p&gt;
&lt;p&gt;Another example that I'd really rather not attempt to use a vector with would be a security descriptor on Windows - variable-length structs followed by more variable length structs. You will run into the same issues with most images, especially WMF or EMF, and to some extent bitmaps. So Stephan's point was that one should _never_ call new[] - mine is that it should be called as infrequently as possible.&lt;/p&gt;
&lt;p&gt;I know a fair bit about macros, though what did escape me and led to this mistake was that you can't check for a keyword with a #if defined. I should have tested exactly that piece of code. I've stepped through literally every single line and&amp;nbsp;return case in the rest of the class, but defines and such are somewhat more annoying to debug.&lt;/p&gt;
&lt;p&gt;You're right that many programmers have a very fragmented knowlege - ran into a guy once that didn't know how to use sprintf, and went though hideously complex C++ hoops to do the same thing. You're also right that there's an amazing variance of errors and brilliance out there - I work on Office, which is over 100 million LOC, and I think every programming approach can be found in there somewhere - partially due to the fact that some of it is 20-25 years old.&lt;/p&gt;
&lt;p&gt;I'm sorely tempted to go back to NULL. That's what I get for attempting to use new features. I only actually need it in one function. Other instances of NULL occur in some of the pointer overloads.&lt;/p&gt;
&lt;p&gt;No, I wasn't planning on it being used on other compilers at the time I started. If I were to do it over, I'd probably use the types set up in stdint.h.&lt;/p&gt;
&lt;p&gt;To be honest, this code has been reviewed by a large number of experts. Some find interesting issues, others don't. The most effective thing that we've done is to create a rigorous test harness. It's one thing to look at code and think it looks good, quite another to _prove_ it works - we caught errors created by the Intel compiler this way, and then proved that we'd coded around them. Most of what's left are things like you caught, where there's no runtime effect, just playing nice with other libraries and code. The remainder of what's left is debatable issues, like how much of the guts to enclose in a namespace, one file or two, whether to put the whole class's external interfaces in a namespace, etc.&lt;/p&gt;
&lt;p&gt;I should still look into getting it into Boost, though I think the legal stuff is the bigger hurdle. We have a perfectly fine license, they do too, not sure why everyone can't just get along... It would be one thing is one license were restrictive, but neither of these are.&lt;/p&gt;&lt;/div&gt;</description><author>dcleblanc</author><pubDate>Wed, 10 Aug 2011 17:35:31 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110810053531P</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;I believe GCC adheres to the standard with NULL, so it's not exactly treated the same as nullptr.&amp;nbsp; It just generates warnings where nullptr would generate errors.&lt;/p&gt;
&lt;p&gt;I often favor the theoretically correct myself.&amp;nbsp; I'm not sure why using a std::vector for safety checks would be a theoretical argument, though; the standard doesn't&amp;nbsp;mandate the safety checks.&amp;nbsp; It seems more of a practical one, since theoretically our code is error-free while practically our code has buffer overflows and the std::vector catches them.&amp;nbsp; Can I have an example where a std::vector can't easily replace operator new[]?&lt;/p&gt;
&lt;p&gt;I agree that macros are a necessary part of the language.&amp;nbsp; It's just that many programmers still use macros inappropriately.&amp;nbsp; I couldn't assume you knew about them.&amp;nbsp; Programmers have surprisingly fragmented knowledge of C++, so someone who knows how to write template specializations but doesn't know how the preprocessor works&amp;nbsp;doesn't sound&amp;nbsp;far-fetched to me.&amp;nbsp; Just look at the code of various open-source libraries other than Boost.&lt;/p&gt;
&lt;p&gt;I don't understand why&amp;nbsp;you need to define nullptr.&amp;nbsp; Can't you use NULL in your code instead?&amp;nbsp; Remember, nullptr isn't the same as NULL.&amp;nbsp; And you'll be making the user deal with errors when their compiler doesn't support it.&lt;/p&gt;
&lt;p&gt;I know the __int8 and __int16 stuff would be difficult to remove.&amp;nbsp; I guess you weren't planning on this library outgrowing MSVC when you started it.&amp;nbsp; If you could do it again today, you'd use typedefs, right?&lt;/p&gt;
&lt;p&gt;I'm not as worried about the namespaces as I am with the macros.&amp;nbsp; But, of course, other issues take priority over both of those.&amp;nbsp;&amp;nbsp;Identifier conflicts&amp;nbsp;would probably cause compile errors anyway.&amp;nbsp; If nobody's complained yet, then your macros have good chances of uniqueness.&lt;/p&gt;
&lt;p&gt;I'd submit issue reports like you prefer, but unfortunately my time is extremely limited.&amp;nbsp;&amp;nbsp;Having your code reviewed by experts is mainly what I'm going for.&amp;nbsp; Boost developers can find and discuss bugs with you just like I have.&amp;nbsp; Even if your library doesn't make it into Boost,&amp;nbsp;the review process&amp;nbsp;would be a nice way to improve it.&lt;/p&gt;&lt;/div&gt;</description><author>Timothy003</author><pubDate>Tue, 09 Aug 2011 20:51:23 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110809085123P</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;That's an interesting issue with the NULL declaration - oops - my bad. I was surprised that my gcc environment didn't have it defined, and then I got the two forms of the definition flipped.&lt;/p&gt;
&lt;p&gt;Stephan and I have gotten into some debates, largely because he works only on a library, where I write features, and work on a wide array of code - some is high level C++, some is C written like you might have seen 20 years ago. He tends more towards what's theoretically correct, and I tend more toward the practical. For example, it is his position that we should never&amp;nbsp;allocate an array of bytes, but always use&amp;nbsp; a std::vector. He's right that the vector is safer, but go try to take apart a TCP/IP header using a vector - wouldn't be fun. Might be possible, but I'm not sure whether anyone coming after could figure out what it was doing. That said, I do use std::vector for many cases where I need an allocated array - an iterator (at least a current implementation) and the [] operator will crash rather than create an exploit. It's also a matter of absolutes - it isn't that we should _never_ call new[], it is that we should prefer std::vector.&lt;/p&gt;
&lt;p&gt;Same sort of thing with macros - there are things you can only do with macros. I don't like them, try not to use them, and often rip them out and turn them into inline functions, but they're not evil - just a dangerous tool (just like the rest of the language).&lt;/p&gt;
&lt;p&gt;The issues you pointed out were good ones - changes made as a result:&lt;/p&gt;
&lt;p&gt;NULL (if needed) is defined as 0&lt;br /&gt;nullptr is only defined if you define NEEDS_NULLPTR_DEFINED 1&lt;br /&gt;intptr_t define is removed&lt;br /&gt;uintptr_t instances changed to size_t, define is removed&lt;/p&gt;
&lt;p&gt;An intentional design decision was to reduce the number of headers required by this class to the least possible. A side-effect is that depending on the environment, you don't always see everything defined that you expect.&lt;/p&gt;
&lt;p&gt;Issues I'm not going to address at the moment -&lt;/p&gt;
&lt;p&gt;The __int8, __int16, etc, are artifacts because the library was originally written for Visual Studio, and I can use them there without including any headers. They're nicely descriptive, which is handy in a world where 'long' has different meanings on different compilers and architectures. So that might be a technical violation of the language, but you can blame the Visual Studio team - I'm just following them. I could go rename them all, but it would make getting a diff between versions a major pain. So that's a won't fix.&lt;/p&gt;
&lt;p&gt;Greater use of namespaces - there's different valid arguments here. Some of the guts of the class work nicely as standalone utilities, especially IntTraits (yes, I know Boost has an analogue). Wrapping these in a namespace would be inconvenient. However, we made the opposite decision with the Visual Studio version. Using a namespace for the overall class seems inappropriate unless it is part of a larger library - again, the Visual Studio version does get wrapped in a namespace, along with a number of other utilities. I'd consider putting more of the implementation into a namespace, but it seems less important than say getting the throw decorations correct.&lt;/p&gt;
&lt;p&gt;Thanks for the input, and there's no offense taken.&lt;/p&gt;&lt;/div&gt;</description><author>dcleblanc</author><pubDate>Tue, 09 Aug 2011 17:37:40 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110809053740P</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;I'm sorry, I made a mistake in that example.&amp;nbsp; I meant &lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;char&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;*p = NULL;&lt;/span&gt;&lt;/span&gt;.&amp;nbsp; Can't believe I missed that after proofreading it dozens of times. &amp;nbsp;:-(&lt;/p&gt;
&lt;p&gt;I'm sorry if I came off harsh.&amp;nbsp; That was certainly not my intent.&amp;nbsp; I used the word 'evil' because Stephan uses it to describe such things, and&amp;nbsp;I put a lot of effort into the examples because I saw some questionable code and wanted to show you exactly my sentiments.&amp;nbsp; I respect you and your work.&amp;nbsp; Please don't take it personally.&amp;nbsp; I'll shorten my explanations from now on.&lt;/p&gt;
&lt;p&gt;Congratulations on keeping this project going for so long!&amp;nbsp; I saw your demo of SafeInt on Channel 9 and came here to check out the library.&amp;nbsp; I'm very grateful that there's such a mature checked-integer library available for free.&lt;/p&gt;&lt;/div&gt;</description><author>Timothy003</author><pubDate>Tue, 09 Aug 2011 03:31:19 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110809033119A</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;OK, well, first of all, you can't do:&lt;/p&gt;
&lt;p&gt;char* c = malloc(1);&lt;/p&gt;
&lt;p&gt;to start with - it emits this:&lt;/p&gt;
&lt;p&gt;zz.cpp(5) : error C2440: 'initializing' : cannot convert from 'void *' to 'char*'&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Conversion from 'void*' to pointer to non-'void' requires an explicit cast&lt;/p&gt;
&lt;p&gt;That's completely independent of whether someone has defined NULL.&lt;/p&gt;
&lt;p&gt;Next, gcc is doing something a little non-standard, by treating NULL the same as nullptr, which is why nullptr exists. That's fine, and the expectation is that the user has almost certainly already defined NULL, so anything I do in this class won't matter. You see the same definition all over many other headers. Note that I don't bother to make it conditional on C++, since this class obviously isn't compiling on a C file.&lt;/p&gt;
&lt;p&gt;Next, as it turns out, I don't need intptr_t, and the instances of uintptr_t can be replaced with size_t. Regardless, uintptr_t and size_t, and the corresponding signed values are guaranteed to have the same size and behavior. Replacing one for the other won't cause any harm, even if it is regrettable. I am well aware of the evils of macros, and have largely tried to avoid them any time possible. I'm also well aware of how to use namespaces, and you may note that these are used internally to the class. At the moment, this version of the class isn't part of an external set of libraries, and thus it would be inappropriate (and clumsy) to add namespaces. There are namespaces defined in the Visual Studio version, which I also maintain.&lt;/p&gt;
&lt;p&gt;I also don't think I've named anything with __, except to follow what Visual Studio has done with __int8, __int16, etc. While that may not be something you're happy with, I can count on these being present in my primary target compiler. That one is a "won't fix".&lt;/p&gt;
&lt;p&gt;Yes, I do know Stephan. He's certainly a very smart guy, though I did report some integer-related bugs in his STL allocator code.&lt;/p&gt;
&lt;p&gt;While we're giving tips, you're more than welcome to report bugs. I'll certainly fix the uintptr_t and intptr_t issues - it was a surprise that my Linux system wouldn't compile when these types were used, and you're right that the defines aren't working as expected. However, please do not use words like 'evil', and it is especially silly to lecture me on modern C++ techniques when you're looking at a class that uses partial template specialization extensively. I'm clearly acquainted with modern programming techniques.&lt;/p&gt;
&lt;p&gt;Here's what I would have preferred to see:&lt;/p&gt;
&lt;p&gt;Issue - uintptr_t and intptr_t shouldn't be defined. intptr_t isn't used, and size_t would work just as well where uintptr_t is used.&lt;/p&gt;
&lt;p&gt;You're also looking at nearly 7000 LOC that have evolved over the last 8 years. It would be a miracle if everything were perfect.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;</description><author>dcleblanc</author><pubDate>Tue, 09 Aug 2011 02:55:38 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110809025538A</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Thanks for listening!&amp;nbsp; Of course, I'll explain.&lt;/p&gt;
&lt;p&gt;The standard library is a special kind of library.&amp;nbsp; It's allowed to declare identifiers&amp;nbsp;that are &lt;em&gt;reserved.&lt;/em&gt;&amp;nbsp; This includes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Names in the global&amp;nbsp;scope&amp;nbsp;that begin with an underscore&lt;/li&gt;
&lt;li&gt;Names anywhere&amp;nbsp;that contain two consecutive underscores&lt;/li&gt;
&lt;li&gt;Names anywhere&amp;nbsp;that begin with an underscore and a capital letter&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That's why you see a lot of underscore usage in standard library headers.&amp;nbsp; This makes sure that the library's internal identifiers don't clash with everyone else's.&amp;nbsp; For this to work, though,&amp;nbsp;everyone else&amp;nbsp;must also not declare reserved identifiers.&amp;nbsp; So the standard libraries get to use names like &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;__foo&lt;/span&gt;&lt;/span&gt;, &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;_Foo&lt;/span&gt;&lt;/span&gt;, and &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;foo__&lt;/span&gt;&lt;/span&gt;, while everything else gets to use names like &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;foo&lt;/span&gt;&lt;/span&gt;, &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;Foo&lt;/span&gt;&lt;/span&gt;, and &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;foo_&lt;/span&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Where does that place non-standard libraries?&amp;nbsp; The Boost convention is to&amp;nbsp;use namespaces.&amp;nbsp; Just as the standard library puts everything into &lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;namespace&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;std&lt;/span&gt;&lt;/span&gt;, Boost puts everything under&amp;nbsp;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;namespace&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;boost&lt;/span&gt;&lt;/span&gt;.&amp;nbsp; Macros ignore namespaces, so Boost capitalizes all macros&amp;nbsp;and&amp;nbsp;prefixes them with the name of the library&amp;nbsp;(e.g. &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;BOOST_UNREACHABLE_RETURN&lt;/span&gt;&lt;/span&gt;).&amp;nbsp; The rationale for that&amp;nbsp;is the same as for namespaces, which I'll get to in a minute.&lt;/p&gt;
&lt;p&gt;In the first piece of code, you define &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;NULL&lt;/span&gt;&lt;/span&gt; as &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;((&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;*)0)&lt;/span&gt;&lt;/span&gt;.&amp;nbsp; There are two problems with this.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The user now cannot write&amp;nbsp;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;char &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;*p = malloc(n);&lt;/span&gt;&lt;/span&gt; because&amp;nbsp;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;void &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;*&lt;/span&gt;&lt;/span&gt; is not implicitly convertible to &lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;char &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;*&lt;/span&gt;&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;GCC has a special definition for&amp;nbsp;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;NULL&lt;/span&gt;&lt;/span&gt;&amp;nbsp;that allows the implicit conversion but gives a warning whenever one tries to&amp;nbsp;convert it to a non-pointer type.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A conforming standard library implementation will define&amp;nbsp;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;NULL&lt;/span&gt;&lt;/span&gt; when the&amp;nbsp;header &lt;span style="font-family: Consolas; color: #a31515; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: x-small;"&gt;&amp;lt;cstddef&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is included.&amp;nbsp; It's required by ISO C++.&amp;nbsp; Every sane implementation has it.&lt;/p&gt;
&lt;p&gt;In the second example, you check for and define&amp;nbsp;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;intptr_t&lt;/span&gt;&lt;/span&gt; and&amp;nbsp;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;uintptr_t&lt;/span&gt;&lt;/span&gt;.&amp;nbsp; This&amp;nbsp;is flawed&amp;nbsp;because those two names are typedefs according to the language.&amp;nbsp; You can't check for them using the preprocessor.&amp;nbsp; Also, consider what could happen&amp;nbsp;when GCC does define the names.&amp;nbsp; Your header would change the meaning of&amp;nbsp;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;intptr_t&lt;/span&gt;&lt;/span&gt; and &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;uintptr_t&lt;/span&gt;&lt;/span&gt;.&amp;nbsp; If you're lucky, the two definitions&amp;nbsp;will agree;&amp;nbsp;&lt;span style="font-family: Consolas; color: #a31515; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: x-small;"&gt;&amp;lt;cstdint&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; would say&amp;nbsp;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;typedef&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;ptrdiff_t intptr_t; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;typedef&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt; &lt;span style="font-family: Consolas; font-size: x-small;"&gt;size_t uintptr_t;&lt;/span&gt;&lt;/span&gt;.&amp;nbsp; However, if the library uses some other types, bad things&amp;nbsp;could happen.&amp;nbsp; Code that uses&amp;nbsp;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;intptr_t&lt;/span&gt;&lt;/span&gt; and &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;uintptr_t&lt;/span&gt;&lt;/span&gt; would&amp;nbsp;then change simply because they included your header.&lt;/p&gt;
&lt;p&gt;Macros are generally&amp;nbsp;avoided in modern C++.&amp;nbsp;&amp;nbsp;&amp;nbsp;They replace all occurrences of the name regardless of where they are.&amp;nbsp; For example, the following code...&lt;/p&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;namespace&lt;/span&gt; boots
{
	&lt;span style="color: blue;"&gt;typedef&lt;/span&gt; std::intptr_t intptr_t;
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;...will be preprocessed into...&lt;/p&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;namespace&lt;/span&gt; boots
{
	&lt;span style="color: blue;"&gt;typedef&lt;/span&gt; std::ptrdiff_t ptrdiff_t;
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It's like doing a find-and-replace-all in your code, the standard library's code, and everyone else's code.&amp;nbsp; Macros are evil.&amp;nbsp; If there's no way to do what you want without macros,&amp;nbsp;then use them, but follow the naming convention so that users won't unknowingly have their code changed.&amp;nbsp; Likewise, don't&amp;nbsp;declare identifiers that are in all capital letters that aren't prefixed by your library name, so that the &lt;em&gt;user's&lt;/em&gt; macros won't change &lt;em&gt;your&lt;/em&gt; code.&lt;/p&gt;
&lt;p&gt;In the last piece of code, you check for and define &lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;nullptr&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.&amp;nbsp; &lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;nullptr&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is not a macro.&amp;nbsp; It's a keyword, and, like typedefs,&amp;nbsp;you can't check for&amp;nbsp;keywords during preprocessing.&lt;/p&gt;
&lt;p&gt;Generally, if a feature isn't available in a particular C++ implementation that you need to support, don't use it.&amp;nbsp;&amp;nbsp;In place&amp;nbsp;of &lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;nullptr&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, you can use &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;NULL&lt;/span&gt;&lt;/span&gt;.&amp;nbsp; If there's no replacement, like with &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;intptr_t&lt;/span&gt;&lt;/span&gt;, then use your own definitions, but put them in your own namespace (or prefix their names if they're macros).&amp;nbsp; Namespaces prevent conflicts with user code and other libraries.&amp;nbsp; You shouldn't define&amp;nbsp;anything&amp;nbsp;outside of your namespace unless you're absolutely certain that the definition is, and will be, unique.&amp;nbsp; Remember:&amp;nbsp;&lt;a title="One Definition Rule - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/One_Definition_Rule"&gt;In any translation unit, a template, type, function, or object can have no more than one definition.&lt;/a&gt;&amp;nbsp; Imagine every library defining&amp;nbsp;the &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;std::vector&lt;/span&gt;&lt;/span&gt;!&lt;/p&gt;
&lt;p&gt;To reiterate,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Standard libraries use names like &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;__foo&lt;/span&gt;&lt;/span&gt;, &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;_Foo&lt;/span&gt;&lt;/span&gt;, &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;foo__&lt;/span&gt;&lt;/span&gt;, and &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;_FOO&lt;/span&gt;&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;Non-standard libraries use names like &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;boots::foo&lt;/span&gt;&lt;/span&gt;, &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;boots::Foo&lt;/span&gt;&lt;/span&gt;, &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;boots::foo_&lt;/span&gt;&lt;/span&gt;, and &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;BOOTS_FOO&lt;/span&gt;&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;Users use names like &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;foo&lt;/span&gt;&lt;/span&gt;, &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;Foo&lt;/span&gt;&lt;/span&gt;, &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;foo_&lt;/span&gt;&lt;/span&gt;, and &lt;span style="font-family: Consolas; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;FOO&lt;/span&gt;&lt;/span&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thanks for taking the time to read this.&amp;nbsp; I'm a passionate C++ programmer who loves using libraries to ease my work.&amp;nbsp; But it's frustrating to see libraries trample over each other.&amp;nbsp; And it's impossible for me to review all the library code&amp;nbsp;by myself.&amp;nbsp; You might know Stephan T. Lavavej--he's&amp;nbsp;a developer of the Visual C++ standard library implementation.&amp;nbsp; He's really good with words.&amp;nbsp; Maybe he could give you some tips.&lt;/p&gt;&lt;/div&gt;</description><author>Timothy003</author><pubDate>Tue, 09 Aug 2011 00:26:44 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110809122644A</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Could you perhaps explain how these are evil?&lt;/p&gt;
&lt;p&gt;If this is really wrong, then there's a number of standard libraries that have bugs. There's 10 different headers in the Microsoft headers that have NULL defined, which is needed because it isn't defined as part of the language. A compiler and platform-independent library such as this one has to define anything that isn't part of the language standard, or it has to include standard headers that will.&lt;/p&gt;
&lt;p&gt;Then uintptr_t and intptr_t are part of the language, but some versions of gcc that are supported by this class don't seem to know that these are keywords, and want them defined. If you have them defined, then these conditional definitions don't matter. Finally, nullptr is part of the newest edition of the standard, and this class is still supported on a number of compilers that are several years old, and you need that either defined as a keyword, or it needs a #define.&lt;/p&gt;
&lt;p&gt;Thanks for your interest, and I'm happy to know that Boost could teach me more about modern C++ programming.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;span style="font-family: Consolas; color: #0000ff; font-size: x-small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&amp;nbsp;&lt;/div&gt;</description><author>dcleblanc</author><pubDate>Mon, 08 Aug 2011 17:22:03 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110808052203P</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Boost has really smart people in its community, and sets ultra-high standards.&amp;nbsp; Libraries are peer-reviewed too, so you'd get a lot of good feedback on your code.&amp;nbsp; For example, I grabbed the latest SafeInt3.hpp, opened it up,&amp;nbsp;and immediately saw this:&lt;/p&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;#&lt;span style="color: blue;"&gt;if&lt;/span&gt; !defined NULL
#define NULL ((&lt;span style="color: blue;"&gt;void&lt;/span&gt;*)0)
#endif
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: green;"&gt;// These two may not be defined, either&lt;/span&gt;
#&lt;span style="color: blue;"&gt;if&lt;/span&gt; !defined uintptr_t
#define uintptr_t size_t
#endif

#&lt;span style="color: blue;"&gt;if&lt;/span&gt; !defined intptr_t
#define intptr_t ptrdiff_t
#endif
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: green;"&gt;// Might need this for gcc and older Microsoft compilers&lt;/span&gt;
#&lt;span style="color: blue;"&gt;if&lt;/span&gt; !defined &lt;span style="color: blue;"&gt;nullptr&lt;/span&gt;
#define &lt;span style="color: blue;"&gt;nullptr&lt;/span&gt; NULL
#endif
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Code like that is evil.&amp;nbsp; The folks at Boost would surely&amp;nbsp;let you know about it, and you'll learn modern C++ programming paradigms, improving the quality of your code.&lt;/p&gt;
&lt;p&gt;I hope you can get the legal stuff out of the way.&amp;nbsp; Good luck!&lt;/p&gt;&lt;/div&gt;</description><author>Timothy003</author><pubDate>Mon, 08 Aug 2011 08:41:01 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110808084101A</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Thanks for reminding me - I think you could probably get an exception for this one, as you're almost certainly allowed to use libraries from Visual Studio, and this version is very, very close to the same thing as in Visual Studio. I do need to go have the discussion with legal people to see how this could work.&lt;/p&gt;
&lt;p&gt;My focus just this moment is to get 3.0.16 up - I'm trying to get the warnings down, and get it to work right with the older compiler Apple likes to use.&lt;/p&gt;&lt;/div&gt;</description><author>dcleblanc</author><pubDate>Tue, 29 Mar 2011 22:31:18 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110329103118P</guid></item><item><title>New Post: SafeInt at Boost?</title><link>http://safeint.codeplex.com/discussions/60193</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I just would like to say that having SafeInt in boost would be very much appreciated. The C++ community would be grateful.&lt;/p&gt;
&lt;p&gt;Many a companies have defacto &amp;nbsp;rules like "no 3rd party libraries allowed except boost". People trust the boost libraries just because the name is so well known and respected, even if they are a bit buggy sometimes.&lt;/p&gt;
&lt;p&gt;Also it would be good PR for MS.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Just my 2 cents.&lt;/p&gt;&lt;/div&gt;</description><author>petke</author><pubDate>Tue, 29 Mar 2011 21:27:34 GMT</pubDate><guid isPermaLink="false">New Post: SafeInt at Boost? 20110329092734P</guid></item><item><title>New Post: Why no assembly?</title><link>http://safeint.codeplex.com/Thread/View.aspx?ThreadId=216022</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;The problem is two-fold. First, the overflow flag doesn't get set for everything. For example, assigning a 32-bit int to a 16-bit int is dangerous, but the CPU doesn't see an overflow. Adding two 16-bit ints won't set the overflow flag, either. There's a bunch of cases that don't set the overflow flag. I haven't checked, but I suspect that you could well run into the same thing on a 64-bit CPU where a 32-bit multiplication doesn't set the overflow flag, though it might because of different assembly instructions.&lt;/p&gt;
&lt;p&gt;The second part of the problem is that as soon as you start using assembly, the compiler decides that you must know what you're doing and disables optimizations. Michael Howard and I tried a test case with multiplication, and the inline assembly came in as _much_ slower than optimized SafeInt.&lt;/p&gt;
&lt;p&gt;We've recently been dinking with what produces the best assembly for a test case like uint32 * uint32, and it is all around upcasting to 64-bit, and then you get some very different numbers of branches depending on how you detect an overflow. If you _really_ want to get hard core about perf, what I'd suggest would be to take the approach I use in SafeInt for the specific operation you want, and then manipulate the logic until the optimizer gives you something you like.&lt;/p&gt;&lt;/div&gt;</description><author>dcleblanc</author><pubDate>Tue, 15 Jun 2010 17:08:03 GMT</pubDate><guid isPermaLink="false">New Post: Why no assembly? 20100615050803P</guid></item><item><title>New Post: Why no assembly?</title><link>http://safeint.codeplex.com/Thread/View.aspx?ThreadId=216022</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Also, after some hacking, I got an equivalent in gcc&lt;/p&gt;
&lt;p&gt;
&lt;div style="color:black;background-color:white"&gt;
&lt;pre&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;limits&amp;gt; 

&lt;span style="color:blue"&gt;using&lt;/span&gt; &lt;span style="color:blue"&gt;namespace&lt;/span&gt; std;

&lt;span style="color:blue"&gt;int&lt;/span&gt; main(&lt;span style="color:blue"&gt;int&lt;/span&gt; argc, &lt;span style="color:blue"&gt;char&lt;/span&gt;* argv[])
{    
    &lt;span style="color:blue"&gt;int&lt;/span&gt; x, y;
    &lt;span style="color:blue"&gt;bool&lt;/span&gt; overflow = &lt;span style="color:blue"&gt;false&lt;/span&gt;;
    x = numeric_limits&amp;lt;&lt;span style="color:blue"&gt;int&lt;/span&gt;&amp;gt;::max();
    y = x + 1;
    asm(&lt;span style="color:#a31515"&gt;&amp;quot;jno no_overflow\n&amp;quot;&lt;/span&gt;
	&lt;span style="color:#a31515"&gt;&amp;quot;mov\t$1, %0\n&amp;quot;&lt;/span&gt;
        &lt;span style="color:#a31515"&gt;&amp;quot;no_overflow:\n&amp;quot;&lt;/span&gt;
       :&lt;span style="color:#a31515"&gt;&amp;quot;=r&amp;quot;&lt;/span&gt;(overflow)
       :&lt;span style="color:#a31515"&gt;&amp;quot;r&amp;quot;&lt;/span&gt;(overflow) 
       );
    &lt;span style="color:blue"&gt;if&lt;/span&gt; (overflow) cout &amp;lt;&amp;lt; &lt;span style="color:#a31515"&gt;&amp;quot;overflow&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; endl;
    &lt;span style="color:blue"&gt;else&lt;/span&gt; cout &amp;lt;&amp;lt; &lt;span style="color:#a31515"&gt;&amp;quot;no overflow&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; endl;
    &lt;span style="color:blue"&gt;return&lt;/span&gt; 0;
}
&lt;/pre&gt;
&lt;/div&gt;
Cheers, Dejan&lt;/p&gt;&lt;/div&gt;</description><author>dddejan</author><pubDate>Tue, 15 Jun 2010 08:02:38 GMT</pubDate><guid isPermaLink="false">New Post: Why no assembly? 20100615080238A</guid></item><item><title>New Post: Why no assembly?</title><link>http://safeint.codeplex.com/Thread/View.aspx?ThreadId=216022</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;I recently encountered the need to check for int overflows in order to speed up the computation in an application we are developing that involves big numbers. We basically use the same trick with extending the size of the operands and checking if the result fits. It is unusual to have to do this when the processors do offer overflow flags and we can access them (although not in a nice way). Since you&amp;nbsp;definitely&amp;nbsp;have more experience in developing with overflows, I was wondering why you are not doing something like this&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10pt;color:blue"&gt;#include&lt;/span&gt;&lt;span style="font-size:10pt"&gt; &lt;span style="color:#a31515"&gt;&amp;lt;iostream&amp;gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:10pt;color:blue"&gt;#include&lt;/span&gt;&lt;span style="font-size:10pt"&gt; &lt;span style="color:#a31515"&gt;&amp;lt;limits&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10pt;color:blue"&gt;using&lt;/span&gt;&lt;span style="font-size:10pt"&gt; &lt;span style="color:blue"&gt;namespace&lt;/span&gt; std;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10pt;color:blue"&gt;#undef&lt;/span&gt;&lt;span style="font-size:10pt"&gt; max&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10pt;color:blue"&gt;#define&lt;/span&gt;&lt;span style="font-size:10pt"&gt; CHECK_OVERFLOW(code, label) \&lt;br&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;code; \&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span style="color:blue"&gt;_asm&lt;/span&gt; { jo label } \&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10pt;color:blue"&gt;int&lt;/span&gt;&lt;span style="font-size:10pt"&gt; main(&lt;span style="color:blue"&gt;int&lt;/span&gt; argc, &lt;span style="color:blue"&gt;char&lt;/span&gt;* argv[])&lt;br&gt;&lt;/span&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span style="color:blue"&gt;int&lt;/span&gt; x, y = 0;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;x = numeric_limits&amp;lt;&lt;span style="color:blue"&gt;int&lt;/span&gt;&amp;gt;::max();&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;CHECK_OVERFLOW(y = x + 1, overflow_label);&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;CHECK_OVERFLOW(x = y + 1, overflow_label); &amp;nbsp;&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;cout &amp;lt;&amp;lt; &lt;span style="color:#a31515"&gt;&amp;quot;no overflow&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; endl;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span style="color:blue"&gt;return&lt;/span&gt; 0;&lt;br&gt;overflow_label:&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;cout &amp;lt;&amp;lt; &lt;span style="color:#a31515"&gt;&amp;quot;overflow&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; endl;&lt;br&gt;}&lt;/p&gt;
&lt;p&gt;Are there conditions where this would fail (like compiler optimizations), or is there other reasons that I'm not seeing?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;</description><author>dddejan</author><pubDate>Tue, 15 Jun 2010 00:40:30 GMT</pubDate><guid isPermaLink="false">New Post: Why no assembly? 20100615124030A</guid></item></channel></rss>