OLD | NEW |
| (Empty) |
1 // Copyright 2010 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 // | |
16 // As of Sept 2010, the implementation of Format() in ATL's CStringT uses a | |
17 // fixed internal buffer of 1024 bytes; any output beyond that point will | |
18 // be silently truncated. (AppendFormat() is affected by the same bug.) | |
19 // A bug has been filed with Microsoft; in the meantime, we provide the | |
20 // following safer implementations of Format/AppendFormat. These functions | |
21 // currently support up to MAX_INT characters and will return an HRESULT | |
22 // error code on overflow or invalid parameters. | |
23 | |
24 #ifndef OMAHA_BASE_SAFE_FORMAT_H_ | |
25 #define OMAHA_BASE_SAFE_FORMAT_H_ | |
26 | |
27 #include <atlstr.h> | |
28 #include <strsafe.h> | |
29 | |
30 namespace omaha { | |
31 | |
32 void SafeCStringWFormatV(CStringW* dest_str, | |
33 LPCWSTR format_str, | |
34 va_list arg_list); | |
35 | |
36 void SafeCStringAFormatV(CStringA* dest_str, | |
37 LPCSTR format_str, | |
38 va_list arg_list); | |
39 | |
40 void SafeCStringWFormat(CStringW* dest_str, LPCWSTR format_str, ...); | |
41 | |
42 void SafeCStringAFormat(CStringA* dest_str, LPCSTR format_str, ...); | |
43 | |
44 void SafeCStringWAppendFormat(CStringW* dest_str, LPCWSTR format_str, ...); | |
45 | |
46 void SafeCStringAAppendFormat(CStringA* dest_str, LPCSTR format_str, ...); | |
47 | |
48 } // namespace omaha | |
49 | |
50 #ifdef UNICODE | |
51 #define SafeCStringFormatV SafeCStringWFormatV | |
52 #define SafeCStringFormat SafeCStringWFormat | |
53 #define SafeCStringAppendFormat SafeCStringWAppendFormat | |
54 #else | |
55 #define SafeCStringFormatV SafeCStringAFormatV | |
56 #define SafeCStringFormat SafeCStringAFormat | |
57 #define SafeCStringAppendFormat SafeCStringAAppendFormat | |
58 #endif // UNICODE | |
59 | |
60 #endif // OMAHA_BASE_SAFE_FORMAT_H_ | |
OLD | NEW |