From 5d46888dc271cc82e2d59adcac815a5acde8c41e Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 6 Jun 2023 15:34:36 +0200 Subject: [PATCH] Revise SAL for "start&length" string parameters Signed-off-by: Simon Rozman --- include/stdex/sal.hpp | 3 +++ include/stdex/sgml.hpp | 10 +++++----- include/stdex/string.hpp | 38 +++++++++++++++++++------------------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/include/stdex/sal.hpp b/include/stdex/sal.hpp index 8da45ac37..072261b76 100644 --- a/include/stdex/sal.hpp +++ b/include/stdex/sal.hpp @@ -36,6 +36,9 @@ #ifndef _In_reads_or_z_ #define _In_reads_or_z_(p) #endif +#ifndef _In_reads_or_z_opt_ +#define _In_reads_or_z_opt_(p) +#endif #ifndef _Inout_ #define _Inout_ diff --git a/include/stdex/sgml.hpp b/include/stdex/sgml.hpp index d2635781e..154373cb3 100644 --- a/include/stdex/sgml.hpp +++ b/include/stdex/sgml.hpp @@ -43,7 +43,7 @@ namespace stdex template inline const T* sgmlend( - _In_reads_or_z_(count) const T* str, + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count) { assert(str || !count); @@ -93,7 +93,7 @@ namespace stdex template inline void sgml2str( _Inout_ std::wstring &dst, - _In_reads_or_z_(count_src) const T* src, _In_ size_t count_src, + _In_reads_or_z_opt_(count_src) const T* src, _In_ size_t count_src, _In_ int skip = 0, _In_ const mapping& offset = mapping(0, 0), _Inout_opt_ mapping_vector* map = nullptr) @@ -185,7 +185,7 @@ namespace stdex /// template inline std::wstring sgml2str( - _In_reads_or_z_(count_src) const T* src, _In_ size_t count_src, + _In_reads_or_z_opt_(count_src) const T* src, _In_ size_t count_src, _In_ int skip = 0, _In_ const mapping& offset = mapping(0, 0), _Inout_opt_ mapping_vector* map = nullptr) @@ -234,7 +234,7 @@ namespace stdex /// inline void str2sgml( _Inout_ std::string &dst, - _In_reads_or_z_(count_src) const wchar_t* src, + _In_reads_or_z_opt_(count_src) const wchar_t* src, _In_ size_t count_src, _In_ size_t what = 0) { @@ -337,7 +337,7 @@ namespace stdex /// \return SGML string /// inline std::string str2sgml( - _In_reads_or_z_(count_src) const wchar_t* src, + _In_reads_or_z_opt_(count_src) const wchar_t* src, _In_ size_t count_src, _In_ size_t what = 0) { diff --git a/include/stdex/string.hpp b/include/stdex/string.hpp index 039d95a39..a7c193218 100644 --- a/include/stdex/string.hpp +++ b/include/stdex/string.hpp @@ -111,7 +111,7 @@ namespace stdex /// \param[in] count Code unit limit /// template - inline size_t islbreak(_In_reads_or_z_(count) const T* chr, _In_ size_t count) + inline size_t islbreak(_In_reads_or_z_opt_(count) const T* chr, _In_ size_t count) { if (count >= 2 && (chr[0] == '\r' && chr[1] == '\n' || chr[0] == '\n' && chr[1] == '\r')) return 2; @@ -126,7 +126,7 @@ namespace stdex /// \param[in] glyph Start of a glyph /// \param[in] count Code unit limit /// - inline size_t glyphlen(_In_reads_or_z_(count) const wchar_t* glyph, size_t count) + inline size_t glyphlen(_In_reads_or_z_opt_(count) const wchar_t* glyph, size_t count) { if (count) { #ifdef _WIN32 @@ -184,7 +184,7 @@ namespace stdex /// template inline const T* strnchr( - _In_reads_or_z_(count) const T* str, + _In_reads_or_z_opt_(count) const T* str, _In_ T chr, _In_ size_t count) { @@ -205,7 +205,7 @@ namespace stdex /// template inline const T* strnichr( - _In_reads_or_z_(count) const T* str, + _In_reads_or_z_opt_(count) const T* str, _In_ T chr, _In_ size_t count, _In_ const std::locale& locale) @@ -230,8 +230,8 @@ namespace stdex /// template inline int strncmp( - _In_reads_or_z_(count1) const T1* str1, _In_ size_t count1, - _In_reads_or_z_(count2) const T2* str2, _In_ size_t count2) + _In_reads_or_z_opt_(count1) const T1* str1, _In_ size_t count1, + _In_reads_or_z_opt_(count2) const T2* str2, _In_ size_t count2) { assert(str1 || !count1); assert(str2 || !count2); @@ -257,8 +257,8 @@ namespace stdex /// template inline int strnicmp( - _In_reads_or_z_(count1) const T1* str1, _In_ size_t count1, - _In_reads_or_z_(count2) const T2* str2, _In_ size_t count2, + _In_reads_or_z_opt_(count1) const T1* str1, _In_ size_t count1, + _In_reads_or_z_opt_(count2) const T2* str2, _In_ size_t count2, _In_ const std::locale& locale) { assert(str1 || !count1); @@ -286,7 +286,7 @@ namespace stdex /// template const T1* strnstr( - _In_reads_or_z_(count) const T1* str, + _In_reads_or_z_opt_(count) const T1* str, _In_z_ const T2* sample, _In_ size_t count) { @@ -315,7 +315,7 @@ namespace stdex /// template inline const T1* strnistr( - _In_reads_or_z_(count) const T1* str, + _In_reads_or_z_opt_(count) const T1* str, _In_z_ const T2* sample, _In_ size_t count, _In_ const std::locale& locale) @@ -366,7 +366,7 @@ namespace stdex /// \cond internal template inline T_bin strtoint( - _In_reads_or_z_(count) const T* str, _In_ size_t count, + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count, _Out_opt_ size_t* end, _In_ int radix, _Out_ uint8_t& flags) @@ -469,7 +469,7 @@ namespace stdex /// template T_bin strtoint( - _In_reads_or_z_(count) const T* str, _In_ size_t count, + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count, _Out_opt_ size_t* end, _In_ int radix) { @@ -534,7 +534,7 @@ namespace stdex /// template inline T_bin strtouint( - _In_reads_or_z_(count) const T* str, + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count, _Out_opt_ size_t* end, _In_ int radix) @@ -567,7 +567,7 @@ namespace stdex /// template inline int32_t strto32( - _In_reads_or_z_(count) const T* str, _In_ size_t count, + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count, _Out_opt_ size_t* end, _In_ int radix) { @@ -586,7 +586,7 @@ namespace stdex /// template inline int64_t strto64( - _In_reads_or_z_(count) const T* str, _In_ size_t count, + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count, _Out_opt_ size_t* end, _In_ int radix) { @@ -606,7 +606,7 @@ namespace stdex /// template inline intptr_t strtoi( - _In_reads_or_z_(count) const T* str, _In_ size_t count, + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count, _Out_opt_ size_t* end, _In_ int radix) { @@ -629,7 +629,7 @@ namespace stdex /// template inline uint32_t strtou32( - _In_reads_or_z_(count) const T* str, _In_ size_t count, + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count, _Out_opt_ size_t* end, _In_ int radix) { @@ -648,7 +648,7 @@ namespace stdex /// template inline uint64_t strtou64( - _In_reads_or_z_(count) const T* str, _In_ size_t count, + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count, _Out_opt_ size_t* end, _In_ int radix) { @@ -668,7 +668,7 @@ namespace stdex /// template inline size_t strtoui( - _In_reads_or_z_(count) const T* str, _In_ size_t count, + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count, _Out_opt_ size_t* end, _In_ int radix) {