Skip to content

Commit 441f493

Browse files
author
Colin Robertson
authored
Add fixes for _SECURE_SCL (#118)
* Clean up obsolete references to STL * Catch some STL stragglers * Per STL, fix obsolete _SECURE_SCL * Fix typos.
1 parent 3f69f0c commit 441f493

13 files changed

+229
-303
lines changed

docs/cpp/containers-modern-cpp.md

Lines changed: 14 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -31,92 +31,34 @@ translation.priority.mt:
3131
- "pt-br"
3232
- "tr-tr"
3333
---
34-
# Containers (Modern C++)
35-
By default, use [vector](../standard-library/vector-class.md) as the default sequential container in C++. This is the equivalent of List\<T> in other languages.
34+
# Containers (Modern C++)
3635

37-
```cpp
38-
vector<string> v;
39-
v.push_back( "Geddy Lee" );
36+
By default, use [vector](../standard-library/vector-class.md) as the preferred sequential container in C++. This is equivalent to `List\<T>` in .NET languages.
4037

38+
```cpp
39+
vector<string> apples;
40+
apples.push_back("Granny Smith");
4141
```
4242

43-
Use [map](../standard-library/map-class.md) (not unordered_map) as the default associative container. Use [set](../standard-library/set-class.md), [multimap](../standard-library/multimap-class.md), [multiset](../standard-library/multiset-class.md) for degenerate & multi cases.
43+
Use [map](../standard-library/map-class.md) (not `unordered_map`) as the default associative container. Use [set](../standard-library/set-class.md), [multimap](../standard-library/multimap-class.md), and [multiset](../standard-library/multiset-class.md) for degenerate & multi cases.
4444

4545
```cpp
46-
map<string, string> phone_book;
46+
map<string, string> apple_color;
4747
// ...
48-
phone_book["Alex Lifeson"] = "+1 (416) 555-1212";
49-
48+
apple_color["Granny Smith"] = "Green";
5049
```
5150

52-
When performance optimization is needed, consider using:
53-
54-
1. the array type when embedding is important - for example, as a class member.
55-
56-
2. unordered associative containers (unordered_map, et al.): Lower per-element overhead (major) and constant-time lookup (potentially major, sometimes minor). Harder to use correctly and efficiently, because of inconveniences and sharp edges.
57-
58-
3. sorted vector. (See: [Algorithms](../cpp/algorithms-modern-cpp.md).)
51+
When performance optimization is needed, consider using:
5952

60-
Don’t use C arrays. (For older APIs, use `f( vec.data(), vec.size() );` .)
53+
1. The [array](../standard-library/array-class-stl.md) type when embedding is important, for example, as a class member.
6154

62-
For another article about containers, see [C++ Standard Library Containers](../standard-library/stl-containers.md).
55+
2. Unordered associative containers such as [unordered_map]((../standard-library/unordered-map-class.md). These have lower per-element overhead and constant-time lookup, but they can be harder to use correctly and efficiently.
6356

64-
## Container Sizes
65-
The following tables show the container sizes, in bytes, for x86 and x64 platforms. (For these purposes, 32-bit ARM is equivalent to x86.) These tables cover release mode, because debug mode contains checking machinery that consumes space and time. The separate columns are for [!INCLUDE[cpp_orcas_long](../cpp/includes/cpp_orcas_long_md.md)] SP1, where `_SECURE_SCL` defaulted to 1, and for [!INCLUDE[cpp_orcas_long](../cpp/includes/cpp_orcas_long_md.md)] SP1 with `_SECURE_SCL` manually set to 0 for maximum speed. Visual C++ in Visual Studio 2010, [!INCLUDE[cpp_dev11_long](../build/includes/cpp_dev11_long_md.md)], and [!INCLUDE[cpp_dev12_long](../build/reference/includes/cpp_dev12_long_md.md)] default `_SECURE_SCL` to 0 (now known as `_ITERATOR_DEBUG_LEVEL`).
57+
3. Sorted `vector`. For more information, see [Algorithms](../cpp/algorithms-modern-cpp.md).
6658

67-
|x86 Container Sizes (Bytes)|VC9 SP1|VC9 SP1<br /><br /> SCL=0|VC10|VC11|
68-
|-----------------------------------|-------------|------------------------|----------|----------|
69-
|vector\<int>|24|16|16|12|
70-
|array\<int, 5>|20|20|20|20|
71-
|deque\<int>|32|32|24|20|
72-
|forward_list\<int>|N/A|N/A|8|4|
73-
|list\<int>|28|12|12|8|
74-
|priority_queue\<int>|28|20|20|16|
75-
|queue\<int>|32|32|24|20|
76-
|stack\<int>|32|32|24|20|
77-
|pair\<int, int>|8|8|8|8|
78-
|tuple\<int, int, int>|16|16|16|12|
79-
|map\<int, int>|32|12|16|8|
80-
|multimap\<int, int>|32|12|16|8|
81-
|set\<int>|32|12|16|8|
82-
|multiset\<int>|32|12|16|8|
83-
|hash_map\<int, int>|72|44|44|32|
84-
|hash_multimap\<int, int>|72|44|44|32|
85-
|hash_set\<int>|72|44|44|32|
86-
|hash_multiset\<int>|72|44|44|32|
87-
|unordered_map\<int, int>|72|44|44|32|
88-
|unordered_multimap\<int, int>|72|44|44|32|
89-
|unordered_set\<int>|72|44|44|32|
90-
ordered_multiset\<int>|72|44|44|32|
91-
|string|28|28|28|24|
92-
|wstring|28|28|28|24|
59+
Don’t use C-style arrays. For older APIs that need direct access to the data, use accessor methods such as `f(vec.data(), vec.size());` instead.
9360

94-
|x64 Container Sizes (Bytes)|VC9 SP1|VC9 SP1<br /><br /> SCL=0|VC10|VC11|
95-
|-----------------------------------|-------------|------------------------|----------|----------|
96-
|vector\<int>|48|32|32|24|
97-
|array\<int, 5>|20|20|20|20|
98-
|deque\<int>|64|64|48|40|
99-
|forward_list\<int>|N/A|N/A|16|8|
100-
|list\<int>|56|24|24|16|
101-
|priority_queue\<int>|56|40|40|32|
102-
|queue\<int>|64|64|48|40|
103-
|stack\<int>|64|64|48|40|
104-
|pair\<int, int>|8|8|8|8|
105-
|tuple\<int, int, int>|16|16|16|12|
106-
|map\<int, int>|64|24|32|16|
107-
|multimap\<int, int>|64|24|32|16|
108-
|set\<int>|64|24|32|16|
109-
|multiset\<int>|64|24|32|16|
110-
|hash_map\<int, int>|144|88|88|64|
111-
|hash_multimap\<int, int>|144|88|88|64|
112-
|hash_set\<int>|144|88|88|64|
113-
|hash_multiset\<int>|144|88|88|64|
114-
|unordered_map\<int, int>|144|88|88|64|
115-
|unordered_multimap\<int, int>|144|88|88|64|
116-
|unordered_set\<int>|144|88|88|64|
117-
ordered_multiset\<int>|144|88|88|64|
118-
|string|40|40|40|32|
119-
|wstring|40|40|40|32|
61+
For more information about containers, see [C++ Standard Library Containers](../standard-library/stl-containers.md).
12062

12163
## See Also
12264
[Welcome Back to C++](../cpp/welcome-back-to-cpp-modern-cpp.md)

docs/security/security-best-practices-for-cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ This article contains information about security tools and practices. Using them
7171
Each `SafeInt` function protects one mathematical operation from an exploitable error. You can use two different kinds of parameters without converting them to the same type. To protect multiple mathematical operations, use the `SafeInt` class.
7272

7373
## Checked Iterators
74-
A checked iterator enforces container boundaries. By default, when a checked iterator is out of bounds, it generates an exception and ends program execution. A checked iterator provides other levels of response that depend on values that are assigned to preprocessor defines such as **_SECURE_SCL_THROWS** and **_ITERATOR_DEBUG_LEVEL**. For example, at **_ITERATOR_DEBUG_LEVEL=2**, a checked iterator provides comprehensive correctness checks in debug mode, which are made available by using asserts. For more information, see [Checked Iterators](../standard-library/checked-iterators.md).
74+
A checked iterator enforces container boundaries. By default, when a checked iterator is out of bounds, it generates an exception and ends program execution. A checked iterator provides other levels of response that depend on values that are assigned to preprocessor defines such as **\_SECURE\_SCL\_THROWS** and **\_ITERATOR\_DEBUG\_LEVEL**. For example, at **\_ITERATOR\_DEBUG\_LEVEL=2**, a checked iterator provides comprehensive correctness checks in debug mode, which are made available by using asserts. For more information, see [Checked Iterators](../standard-library/checked-iterators.md) and [\_ITERATOR\_DEBUG\_LEVEL](../standard-library/iterator-debug-level.md).
7575

7676
## Code Analysis for Managed Code
7777
Code Analysis for Managed Code, also known as FxCop, checks assemblies for conformance to the.NET Framework design guidelines. FxCop analyzes the code and metadata in each assembly to check for defects in the following areas:

docs/standard-library/basic-string-class.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3322,10 +3322,8 @@ The string str1 reassigned with string str3c is: World.
33223322
Provides a reference to the character with a specified index in a string.
33233323

33243324
```
3325-
const_reference operator[](size_type _Off) const;
3326-
3327-
3328-
reference operator[](size_type _Off);
3325+
const_reference operator[](size_type _Off) const;
3326+
reference operator[](size_type _Off);
33293327
```
33303328

33313329
### Parameters
@@ -3344,7 +3342,7 @@ reference operator[](size_type _Off);
33443342

33453343
The reference returned may be invalidated by string reallocations or modifications for the non- **const** strings.
33463344

3347-
When compiling with _SECURE_SCL 1, a runtime error will occur if you attempt to access an element outside the bounds of the string. See [Checked Iterators](../standard-library/checked-iterators.md) for more information.
3345+
When compiling with [\_ITERATOR\_DEBUG\_LEVEL](../standard-library/iterator-debug-level.md) set to 1 or 2, a runtime error will occur if you attempt to access an element outside the bounds of the string. For more information, see [Checked Iterators](../standard-library/checked-iterators.md).
33483346

33493347
### Example
33503348

0 commit comments

Comments
 (0)