summaryrefslogtreecommitdiff
path: root/ACE/ace/checked_iterator.h
diff options
context:
space:
mode:
authorWilliam R. Otte <wotte@dre.vanderbilt.edu>2008-03-04 14:51:23 +0000
committerWilliam R. Otte <wotte@dre.vanderbilt.edu>2008-03-04 14:51:23 +0000
commit99aa8c60282c7b8072eb35eb9ac815702f5bf586 (patch)
treebda96bf8c3a4c2875a083d7b16720533c8ffeaf4 /ACE/ace/checked_iterator.h
parentc4078c377d74290ebe4e66da0b4975da91732376 (diff)
downloadATCD-99aa8c60282c7b8072eb35eb9ac815702f5bf586.tar.gz
undoing accidental deletion
Diffstat (limited to 'ACE/ace/checked_iterator.h')
-rw-r--r--ACE/ace/checked_iterator.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/ACE/ace/checked_iterator.h b/ACE/ace/checked_iterator.h
new file mode 100644
index 00000000000..ac5e44f6dfc
--- /dev/null
+++ b/ACE/ace/checked_iterator.h
@@ -0,0 +1,58 @@
+// -*- C++ -*-
+
+#ifndef ACE_CHECKED_ITERATOR_H
+#define ACE_CHECKED_ITERATOR_H
+
+/**
+ * @file checked_iterator.h
+ *
+ * @brief Checked iterator factory function.
+ *
+ * Some compilers (e.g. MSVC++ >= 8) issue security related
+ * diagnostics if algorithms such as std::copy() are used in an unsafe
+ * way. Normally this isn't an issue if STL container iterators are
+ * used in conjuction with the standard algorithms. However, in cases
+ * where application-specific iterators are use with standard
+ * algorithms that could potentially overrun a buffer, extra care must
+ * be taken to prevent such an overrun. If supported, checked
+ * iterators can be used to address the potential destination buffer
+ * overrun.
+ *
+ * This header provides function templates that generate the
+ * appropriate checked iterator. In cases where checked iterators are
+ * not supported, the pointer passed to the function is returned
+ * instead.
+ *
+ * $Id$
+ *
+ * @internal The functions and types in this header are meant for
+ * internal use. They may change at any point between
+ * releases.
+ *
+ * @author Ossama Othman
+ */
+
+# if defined (_MSC_VER) && (_MSC_FULL_VER >= 140050000)
+// Checked iterators are currently only supported in MSVC++ 8 or better.
+# include <iterator>
+# endif /* _MSC_VER >= 1400 */
+
+# if defined (_MSC_VER) && (_MSC_FULL_VER >= 140050000)
+template <typename PTR>
+stdext::checked_array_iterator<PTR>
+ACE_make_checked_array_iterator (PTR buf, size_t len)
+{
+ return stdext::checked_array_iterator<PTR> (buf, len);
+}
+# else
+template <typename PTR>
+PTR
+ACE_make_checked_array_iterator (PTR buf, size_t /* len */)
+{
+ // Checked iterators are unsupported. Just return the pointer to
+ // the buffer itself.
+ return buf;
+}
+# endif /* _MSC_VER >= 1400 */
+
+#endif /* ACE_CHECKED_ITERATOR_H */