Turn assert() into _Analysis_assume_ on Release builds

While runtime asserts also served as MSVC Code Analysis hints, the lack
of asserts in Release builds provides no hints to Code Analysis which
rises a lot of warnings then.

Maybe I should learn how to use SAL to annotate <ptr, len> parameter
pairs to allow ptr==nullptr when and only when len==0? 😇

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2023-10-03 15:13:42 +02:00
parent 9ba4b21cef
commit ab8d37ee75
12 changed files with 227 additions and 231 deletions

View File

@ -7,7 +7,6 @@
#include "compat.hpp"
#include "stream.hpp"
#include <assert.h>
#include <cstdint>
#include <string>
#include <vector>
@ -71,7 +70,7 @@ namespace stdex
template<class _Elem, class _Traits, class _Ax>
void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_bytecount_(size) const void *data, _In_ size_t size, _In_opt_ bool is_last = true)
{
assert(data || !size);
_Assume_(data || !size);
// Preallocate output
out.reserve(out.size() + enc_size(size));
@ -191,7 +190,7 @@ namespace stdex
virtual _Success_(return != 0) size_t write(
_In_reads_bytes_opt_(length) const void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
for (size_t i = 0;; i++) {
if (m_num >= 3) {
if (++m_num_blocks > m_max_blocks) {
@ -386,7 +385,7 @@ namespace stdex
virtual _Success_(return != 0 || length == 0) size_t read(
_Out_writes_bytes_to_opt_(length, return) void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
for (size_t to_read = length;;) {
if (m_temp_len >= to_read) {
memcpy(data, m_temp + m_temp_off, to_read);

View File

@ -5,6 +5,7 @@
#pragma once
#include <assert.h>
#include <stddef.h>
#ifdef _WIN32
#include <sal.h>
@ -148,10 +149,6 @@
#define _Null_terminated_
#endif
#ifndef _Analysis_assume_
#define _Analysis_assume_(p)
#endif
#ifndef _Likely_
#if _HAS_CXX20
#define _Likely_ [[likely]]
@ -194,6 +191,15 @@ size_t _countof(T (&arr)[N])
}
#endif
#ifndef _Analysis_assume_
#define _Analysis_assume_(p)
#endif
#ifdef NDEBUG
#define _Assume_(p) _Analysis_assume_(p)
#else
#define _Assume_(p) assert(p)
#endif
#ifdef __APPLE__
#define off64_t off_t
#define lseek64 lseek

View File

@ -7,7 +7,6 @@
#include "compat.hpp"
#include "system.hpp"
#include <assert.h>
#include <stdint.h>
#ifndef LITTLE_ENDIAN
@ -114,10 +113,10 @@ namespace stdex
return *reinterpret_cast<double*>(&r);
}
inline void byteswap(_Inout_ uint8_t* value) { assert(value); *value = byteswap(*value); }
inline void byteswap(_Inout_ uint16_t* value) { assert(value); *value = byteswap(*value); }
inline void byteswap(_Inout_ uint32_t* value) { assert(value); *value = byteswap(*value); }
inline void byteswap(_Inout_ uint64_t* value) { assert(value); *value = byteswap(*value); }
inline void byteswap(_Inout_ uint8_t* value) { _Assume_(value); *value = byteswap(*value); }
inline void byteswap(_Inout_ uint16_t* value) { _Assume_(value); *value = byteswap(*value); }
inline void byteswap(_Inout_ uint32_t* value) { _Assume_(value); *value = byteswap(*value); }
inline void byteswap(_Inout_ uint64_t* value) { _Assume_(value); *value = byteswap(*value); }
inline void byteswap(_Inout_ char* value) { byteswap(reinterpret_cast<uint8_t*>(value)); }
inline void byteswap(_Inout_ int8_t* value) { byteswap(reinterpret_cast<uint8_t*>(value)); }

View File

@ -75,7 +75,7 @@ namespace stdex
virtual void hash(_In_reads_bytes_opt_(length) const void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
// Compute number of bytes mod 64.
size_t j = static_cast<size_t>((m_counter[0] >> 3) & 63);
@ -88,8 +88,8 @@ namespace stdex
// Transform as many times as possible.
size_t i, remainder = 64 - j;
if (length >= remainder) {
assert(j < 64 && j + remainder <= 64);
assert(remainder <= length);
_Assume_(j < 64 && j + remainder <= 64);
_Assume_(remainder <= length);
memcpy(m_queue + j, data, remainder);
hash_block();
for (i = remainder; i + 64 <= length; i += 64) {
@ -110,8 +110,8 @@ namespace stdex
i = 0;
// Buffer remaining input.
assert(j < 64 && j + length - i <= 64);
assert(i <= length);
_Assume_(j < 64 && j + length - i <= 64);
_Assume_(i <= length);
memcpy(m_queue + j, reinterpret_cast<const uint8_t*>(data) + i, length - i);
}
@ -240,7 +240,7 @@ namespace stdex
0x2d02ef8d
};
assert(data || !length);
_Assume_(data || !length);
for (size_t i = 0; i < length; i++)
m_value = crc32_table[(m_value ^ reinterpret_cast<const uint8_t*>(data)[i]) & 0xff] ^ (m_value >> 8);
}

View File

@ -6,7 +6,6 @@
#pragma once
#include "compat.hpp"
#include <assert.h>
#include <cstdint>
#include <string>
#include <vector>
@ -38,7 +37,7 @@ namespace stdex
template<class _Elem, class _Traits, class _Ax>
void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_bytecount_(size) const void *data, _In_ size_t size)
{
assert(data || !size);
_Assume_(data || !size);
// Preallocate output
out.reserve(out.size() + enc_size(size));

View File

@ -11,7 +11,6 @@
#include "sgml.hpp"
#include "string.hpp"
#include "system.hpp"
#include <assert.h>
#include <stdarg.h>
#include <stdint.h>
#include <math.h>
@ -203,7 +202,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
this->interval.start = this->interval.end = start;
return true;
@ -237,7 +236,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
this->interval.end = (this->interval.start = start) + 1;
return true;
@ -269,7 +268,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
if (text[start] == '&') {
// SGML entity
@ -311,7 +310,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
bool r;
if (flags & match_case_insensitive) {
@ -352,7 +351,7 @@ namespace stdex
sgml_parser(locale),
m_invert(invert)
{
assert(chr || !count);
_Assume_(chr || !count);
wchar_t buf[3];
size_t chr_end;
m_chr.assign(count ? next_sgml_cp(chr, 0, count, chr_end, buf) : L"");
@ -364,7 +363,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
wchar_t buf[3];
const wchar_t* chr = next_sgml_cp(text, start, end, this->interval.end, buf);
@ -403,7 +402,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
bool r =
((flags & match_multiline) || !islbreak(text[start])) &&
@ -445,7 +444,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
wchar_t buf[3];
const wchar_t* chr = next_sgml_cp(text, start, end, this->interval.end, buf);
@ -482,7 +481,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
bool r = std::use_facet<std::ctype<T>>(this->m_locale).is(std::ctype_base::punct, text[start]);
if ((r && !m_invert) || (!r && m_invert)) {
@ -522,7 +521,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
wchar_t buf[3];
const wchar_t* chr = next_sgml_cp(text, start, end, this->interval.end, buf);
@ -556,7 +555,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
bool r =
((flags & match_multiline) || !islbreak(text[start])) &&
@ -598,7 +597,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
wchar_t buf[3];
const wchar_t* chr = next_sgml_cp(text, start, end, this->interval.end, buf);
@ -631,7 +630,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
bool r = start == 0 || (start <= end && islbreak(text[start - 1]));
if ((r && !m_invert) || (!r && m_invert)) {
this->interval.end = this->interval.start = start;
@ -669,7 +668,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
bool r = islbreak(text[start]);
if ((r && !m_invert) || (!r && m_invert)) {
this->interval.end = this->interval.start = start;
@ -745,7 +744,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
const T* set = m_set.c_str();
size_t r = (flags & match_case_insensitive) ?
@ -793,7 +792,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
wchar_t buf[3];
const wchar_t* chr = next_sgml_cp(text, start, end, this->interval.end, buf);
@ -837,7 +836,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
size_t
m = m_str.size(),
n = std::min<size_t>(end - start, m);
@ -881,7 +880,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
const wchar_t* str = m_str.c_str();
const bool case_insensitive = flags & match_case_insensitive ? true : false;
const auto& ctype = std::use_facet<std::ctype<wchar_t>>(m_locale);
@ -931,7 +930,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.start = this->interval.end = start;
for (size_t i = 0; ; i++) {
if ((!m_greedy && i >= m_min_iterations) || i >= m_max_iterations)
@ -983,7 +982,7 @@ namespace stdex
_In_ const std::locale& locale = std::locale()) :
basic_parser<T>(locale)
{
assert(el || !count);
_Assume_(el || !count);
m_collection.reserve(count);
for (size_t i = 0; i < count; i++)
m_collection.push_back(el[i]);
@ -1033,7 +1032,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
for (auto i = this->m_collection.begin(); i != this->m_collection.end(); ++i) {
if (!(*i)->match(text, this->interval.end, end, flags)) {
@ -1092,7 +1091,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
hit_offset = 0;
for (auto i = this->m_collection.begin(); i != this->m_collection.end(); ++i, ++hit_offset) {
if ((*i)->match(text, start, end, flags)) {
@ -1163,7 +1162,7 @@ namespace stdex
protected:
void build(_In_reads_(count) const T* str_z, _In_ size_t count)
{
assert(str_z || !count);
_Assume_(str_z || !count);
if (count) {
size_t offset, n;
for (
@ -1224,7 +1223,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
for (auto& el: this->m_collection)
el->invalidate();
if (match_recursively(text, start, end, flags)) {
@ -1334,7 +1333,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
for (this->interval.end = start, this->value = 0; this->interval.end < end && text[this->interval.end];) {
size_t dig;
if (m_digit_0->match(text, this->interval.end, end, flags)) { dig = 0; this->interval.end = m_digit_0->interval.end; }
@ -1405,7 +1404,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (m_digits->match(text, start, end, flags)) {
// Leading part match.
this->value = m_digits->value;
@ -1512,7 +1511,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
for (this->interval.end = start, this->value = 0; this->interval.end < end && text[this->interval.end];) {
size_t dig;
if (m_digit_0->match(text, this->interval.end, end, flags)) { dig = 0; this->interval.end = m_digit_0->interval.end; }
@ -1607,7 +1606,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
size_t
dig[5] = { (size_t)-1, (size_t)-1, (size_t)-1, (size_t)-1, (size_t)-1 },
end2;
@ -1711,7 +1710,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (numerator->match(text, start, end, flags) &&
fraction_line->match(text, numerator->interval.end, end, flags) &&
denominator->match(text, fraction_line->interval.end, end, flags))
@ -1776,7 +1775,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
const int space_match_flags = flags & ~match_multiline; // Spaces in score must never be broken in new line.
@ -1863,7 +1862,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (positive_sign && positive_sign->match(text, this->interval.end, end, flags)) {
this->interval.end = positive_sign->interval.end;
@ -1953,7 +1952,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (positive_sign && positive_sign->match(text, this->interval.end, end, flags)) {
@ -2088,7 +2087,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (positive_sign && positive_sign->match(text, this->interval.end, end, flags)) {
@ -2250,7 +2249,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (positive_sign->match(text, this->interval.end, end, flags)) {
@ -2389,7 +2388,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
value.s_addr = 0;
@ -2509,7 +2508,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
if (text[start] == '-' ||
text[start] == '_' ||
@ -2547,7 +2546,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
wchar_t buf[3];
const wchar_t* chr = next_sgml_cp(text, start, end, this->interval.end, buf);
@ -2624,7 +2623,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
memset(&value, 0, sizeof(value));
@ -2828,7 +2827,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
if (('A' <= text[start] && text[start] <= 'Z') ||
('a' <= text[start] && text[start] <= 'z') ||
@ -2882,7 +2881,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
wchar_t buf[3];
const wchar_t* chr = next_sgml_cp(text, start, end, this->interval.end, buf);
@ -2931,7 +2930,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
size_t i = start, count;
for (count = 0; i < end && text[i] && count < 127; count++) {
if (m_domain_char->match(text, i, end, flags) &&
@ -3005,7 +3004,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
if (text[start] == '-' ||
text[start] == '.' ||
@ -3056,7 +3055,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
wchar_t buf[3];
const wchar_t* chr = next_sgml_cp(text, start, end, this->interval.end, buf);
@ -3104,7 +3103,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
if (text[start] == '-' ||
text[start] == '.' ||
@ -3156,7 +3155,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
wchar_t buf[3];
const wchar_t* chr = next_sgml_cp(text, start, end, this->interval.end, buf);
@ -3204,7 +3203,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
if (text[start] == '/' ||
text[start] == '-' ||
@ -3260,7 +3259,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start]) {
wchar_t buf[3];
const wchar_t* chr = next_sgml_cp(text, start, end, this->interval.end, buf);
@ -3321,7 +3320,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
path.start = start;
@ -3488,7 +3487,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
@ -3827,7 +3826,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (username->match(text, start, end, flags) &&
m_at->match(text, username->interval.end, end, flags))
@ -3931,7 +3930,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (emoticon && emoticon->match(text, start, end, flags)) {
if (apex) apex->invalidate();
@ -4057,7 +4056,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
const int space_match_flags = flags & ~match_multiline; // Spaces in dates must never be broken in new line.
if ((m_format_mask & date_format_dmy) == date_format_dmy) {
@ -4323,7 +4322,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (hour->match(text, start, end, flags) &&
m_separator->match(text, hour->interval.end, end, flags) &&
@ -4428,7 +4427,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
@ -4549,7 +4548,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
size_t safe_digit_end = start, safe_value_size = 0;
bool has_digits = false, after_digit = false, in_parentheses = false, after_parentheses = false;
@ -4567,7 +4566,7 @@ namespace stdex
}
for (;;) {
assert(text || this->interval.end >= end);
_Assume_(text || this->interval.end >= end);
if (this->interval.end >= end || !text[this->interval.end])
break;
if (m_digit->match(text, this->interval.end, end, flags)) {
@ -4697,7 +4696,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
const auto& ctype = std::use_facet<std::ctype<T>>(this->m_locale);
const bool case_insensitive = flags & match_case_insensitive ? true : false;
struct country_t {
@ -4990,7 +4989,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
const auto& ctype = std::use_facet<std::ctype<T>>(this->m_locale);
const bool case_insensitive = flags & match_case_insensitive ? true : false;
size_t n, available, next;
@ -5133,7 +5132,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
for (;;) {
if (this->interval.end >= end || !text[this->interval.end])
@ -5178,7 +5177,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start < end && text[start] == '-') {
this->interval.end = (this->interval.start = start) + 1;
return true;
@ -5228,7 +5227,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
const auto& ctype = std::use_facet<std::ctype<T>>(this->m_locale);
const bool case_insensitive = flags & match_case_insensitive ? true : false;
@ -5471,7 +5470,7 @@ namespace stdex
static bool check11(
_In_count_(num_part1) const T* part1, _In_ size_t num_part1)
{
assert(part1 && num_part1 >= 1);
_Assume_(part1 && num_part1 >= 1);
uint32_t nominator = 0, ponder = 2;
for (size_t i = num_part1 - 1; i--; ++ponder)
nominator += (part1[i] - '0') * ponder;
@ -5485,8 +5484,8 @@ namespace stdex
_In_count_(num_part1) const T* part1, _In_ size_t num_part1,
_In_count_(num_part2) const T* part2, _In_ size_t num_part2)
{
assert(part1 || !num_part1);
assert(part2 && num_part2 >= 1);
_Assume_(part1 || !num_part1);
_Assume_(part2 && num_part2 >= 1);
uint32_t nominator = 0, ponder = 2;
for (size_t i = num_part2 - 1; i--; ++ponder)
nominator += (part2[i] - '0') * ponder;
@ -5503,9 +5502,9 @@ namespace stdex
_In_count_(num_part2) const T* part2, _In_ size_t num_part2,
_In_count_(num_part3) const T* part3, _In_ size_t num_part3)
{
assert(part1 || !num_part1);
assert(part2 || !num_part2);
assert(part3 && num_part3 >= 1);
_Assume_(part1 || !num_part1);
_Assume_(part2 || !num_part2);
_Assume_(part3 && num_part3 >= 1);
uint32_t nominator = 0, ponder = 2;
for (size_t i = num_part3 - 1; i--; ++ponder)
nominator += (part3[i] - '0') * ponder;
@ -5566,7 +5565,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
has_digits = false;
has_charge = false;
@ -5634,10 +5633,10 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
assert(text || this->interval.end >= end);
_Assume_(text || this->interval.end >= end);
if (this->interval.end < end && text[this->interval.end]) {
if (text[this->interval.end] == '\r') {
this->interval.end++;
@ -5670,7 +5669,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (m_line_break.match(text, this->interval.end, end, flags)) {
this->interval.end = m_line_break.interval.end;
@ -5707,10 +5706,10 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
assert(text || this->interval.end >= end);
_Assume_(text || this->interval.end >= end);
if (m_space.match(text, this->interval.end, end, flags)) {
this->interval.start = start;
this->interval.end = m_space.interval.end;
@ -5741,7 +5740,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
for (;;) {
if (this->interval.end < end && text[this->interval.end]) {
@ -5795,14 +5794,14 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (this->interval.end < end && text[this->interval.end] != '"')
goto error;
this->interval.end++;
content.start = this->interval.end;
for (;;) {
assert(text || this->interval.end >= end);
_Assume_(text || this->interval.end >= end);
if (this->interval.end < end && text[this->interval.end]) {
if (text[this->interval.end] == '"') {
content.end = this->interval.end;
@ -5861,7 +5860,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (string.match(text, this->interval.end, end, flags)) {
token.invalidate();
@ -5905,7 +5904,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (name.match(text, this->interval.end, end, flags))
this->interval.end = name.interval.end;
@ -5913,7 +5912,7 @@ namespace stdex
goto error;
while (m_space.match(text, this->interval.end, end, flags))
this->interval.end = m_space.interval.end;
assert(text || this->interval.end >= end);
_Assume_(text || this->interval.end >= end);
if (this->interval.end < end && text[this->interval.end] == '=')
this->interval.end++;
else
@ -5960,7 +5959,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (start + 2 < end &&
text[start] == '*' &&
text[start + 1] == '/' &&
@ -5992,7 +5991,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (type.match(text, this->interval.end, end, flags))
this->interval.end = type.interval.end;
@ -6047,7 +6046,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
if (!http_media_range::match(text, start, end, flags))
goto error;
params.clear();
@ -6105,7 +6104,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
for (;;) {
if (this->interval.end < end && text[this->interval.end]) {
@ -6147,7 +6146,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
value = 0;
this->interval.end = start;
for (;;) {
@ -6198,7 +6197,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
for (;;) {
if (this->interval.end < end && text[this->interval.end]) {
@ -6231,11 +6230,11 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
http_url_path_segment s;
this->interval.end = start;
segments.clear();
assert(text || this->interval.end >= end);
_Assume_(text || this->interval.end >= end);
if (this->interval.end < end && text[this->interval.end] != '/')
goto error;
this->interval.end++;
@ -6287,7 +6286,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
name.start = this->interval.end;
for (;;) {
@ -6373,7 +6372,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (this->interval.end + 7 <= end && stdex::strnicmp(text + this->interval.end, 7, "http://", (size_t)-1, m_locale) == 0) {
@ -6470,7 +6469,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
components.clear();
for (;;) {
@ -6538,7 +6537,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
size_t celi_del = 0, decimalni_del = 0, decimalni_del_n = 1;
this->interval.end = start;
for (;;) {
@ -6602,7 +6601,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || end <= start);
_Assume_(text || end <= start);
if (start < end && text[start] == '*') {
this->interval.end = (this->interval.start = start) + 1;
return true;
@ -6630,7 +6629,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
size_t konec_vrednosti;
this->interval.end = start;
if (asterisk.match(text, this->interval.end, end, flags)) {
@ -6697,7 +6696,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (this->interval.end < end && text[this->interval.end] == '$')
this->interval.end++;
@ -6756,7 +6755,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (name.match(text, this->interval.end, end, flags))
this->interval.end = name.interval.end;
@ -6838,7 +6837,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
type.start = this->interval.end;
for (;;) {
@ -6919,7 +6918,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
type.start = this->interval.end;
for (;;) {
@ -7029,7 +7028,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
for (;;) {
@ -7161,7 +7160,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (m_line_break.match(text, this->interval.end, end, flags) ||
@ -7342,7 +7341,7 @@ namespace stdex
_In_ size_t end = (size_t)-1,
_In_ int flags = match_default)
{
assert(text || start >= end);
_Assume_(text || start >= end);
this->interval.end = start;
if (m_quote->match(text, this->interval.end, end, flags)) {
this->interval.end = m_quote->interval.end;
@ -7387,7 +7386,7 @@ namespace stdex
m_hex->match(text, m_uni->interval.end, std::min(m_uni->interval.end + 4, end), flags | match_case_insensitive) &&
m_hex->interval.size() == 4 /* JSON requests 4-digit Unicode sequneces: \u.... */)
{
assert(m_hex->value <= 0xffff);
_Assume_(m_hex->value <= 0xffff);
if (sizeof(T) == 1) {
if (m_hex->value > 0x7ff) {
value += (T)(0xe0 | ((m_hex->value >> 12) & 0x0f));

View File

@ -6,7 +6,6 @@
#pragma once
#include "compat.hpp"
#include <assert.h>
#include <condition_variable>
#include <mutex>
#include <tuple>
@ -58,7 +57,7 @@ namespace stdex
const std::lock_guard<std::mutex> lg(m_mutex);
#ifdef _DEBUG
size_t tail = wrap(m_head + m_size);
assert(size <= (m_head <= tail ? CAPACITY - tail : m_head - tail));
_Assume_(size <= (m_head <= tail ? CAPACITY - tail : m_head - tail));
#endif
m_size += size;
}
@ -93,7 +92,7 @@ namespace stdex
const std::lock_guard<std::mutex> lg(m_mutex);
#ifdef _DEBUG
size_t tail = wrap(m_head + m_size);
assert(size <= (m_head < tail ? m_size : CAPACITY - m_head));
_Assume_(size <= (m_head < tail ? m_size : CAPACITY - m_head));
#endif
m_head = wrap(m_head + size);
m_size -= size;

View File

@ -9,7 +9,6 @@
#include "mapping.hpp"
#include "sgml_unicode.hpp"
#include "string.hpp"
#include <assert.h>
#include <exception>
#include <string>
@ -19,8 +18,8 @@ namespace stdex
template <class T>
inline const wchar_t* sgml2uni(_In_reads_or_z_(count) const T* entity, _In_ size_t count)
{
assert(entity && count);
assert(count < 2 || entity[0] != '#'); // No numeric entities
_Assume_(entity && count);
_Assume_(count < 2 || entity[0] != '#'); // No numeric entities
for (size_t i = 0, j = _countof(sgml_unicode); i < j; ) {
size_t m = (i + j) / 2;
@ -47,7 +46,7 @@ namespace stdex
inline const T* sgmlend(
_In_reads_or_z_opt_(count) const T* str, _In_ size_t count)
{
assert(str || !count);
_Assume_(str || !count);
for (size_t i = 0; i < count; i++) {
if (str[i] == ';')
return str + i;
@ -97,7 +96,7 @@ namespace stdex
_In_ const mapping<size_t>& offset = mapping<size_t>(0, 0),
_Inout_opt_ mapping_vector<size_t>* map = nullptr)
{
assert(src || !count_src);
_Assume_(src || !count_src);
const bool
skip_quot = (skip & sgml_quot) == 0,
@ -237,8 +236,8 @@ namespace stdex
_In_ const mapping<size_t>& offset = mapping<size_t>(0, 0),
_Inout_opt_ mapping_vector<size_t>* map = nullptr)
{
assert(dst || !count_dst);
assert(src || !count_src);
_Assume_(dst || !count_dst);
_Assume_(src || !count_src);
static const std::invalid_argument buffer_overrun("buffer overrun");
const bool
@ -400,7 +399,7 @@ namespace stdex
_In_ const mapping<size_t>& offset = mapping<size_t>(0, 0),
_Inout_opt_ mapping_vector<size_t>* map = nullptr)
{
assert(dst || !count_dst);
_Assume_(dst || !count_dst);
if (count_dst)
dst[0] = 0;
if (map)
@ -454,7 +453,7 @@ namespace stdex
/// \cond internal
inline const char* chr2sgml(_In_reads_or_z_(count) const wchar_t* entity, _In_ size_t count)
{
assert(entity && count);
_Assume_(entity && count);
const wchar_t e2 = entity[0];
for (size_t i = 0, j = _countof(unicode_sgml); i < j; ) {
@ -493,7 +492,7 @@ namespace stdex
_In_reads_or_z_opt_(count_src) const wchar_t* src, _In_ size_t count_src,
_In_ size_t what = 0)
{
assert(src || !count_src);
_Assume_(src || !count_src);
const bool
do_ascii = (what & sgml_full) == 0,
@ -632,8 +631,8 @@ namespace stdex
_In_reads_or_z_opt_(count_src) const wchar_t* src, _In_ size_t count_src,
_In_ size_t what = 0)
{
assert(dst || !count_dst);
assert(src || !count_src);
_Assume_(dst || !count_dst);
_Assume_(src || !count_src);
static const std::invalid_argument buffer_overrun("buffer overrun");
const bool
@ -695,7 +694,7 @@ namespace stdex
else {
char tmp[3 + 8 + 1 + 1];
int m = snprintf(tmp, _countof(tmp), "&#x%x;", src[i++]);
assert(m >= 0);
_Assume_(m >= 0);
if (static_cast<size_t>(m) >= count_dst)
throw buffer_overrun;
memcpy(dst + j, tmp, m * sizeof(char)); j += m;
@ -733,7 +732,7 @@ namespace stdex
}
char tmp[3 + 8 + 1 + 1];
int m = snprintf(tmp, _countof(tmp), "&#x%x;", unicode);
assert(m >= 0);
_Assume_(m >= 0);
if (static_cast<size_t>(m) >= count_dst)
throw buffer_overrun;
memcpy(dst + j, tmp, m * sizeof(char)); j += m;
@ -805,7 +804,7 @@ namespace stdex
_In_reads_or_z_opt_(count_src) const wchar_t* src, _In_ size_t count_src,
_In_ size_t what = 0)
{
assert(dst || !count_dst);
_Assume_(dst || !count_dst);
if (count_dst)
dst[0] = 0;
return wstr2sgmlcat(dst, count_dst, src, count_src, what);

View File

@ -13,7 +13,6 @@
#include "string.hpp"
#include "system.hpp"
#include "unicode.hpp"
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#if defined(_WIN32)
@ -965,7 +964,7 @@ namespace stdex
///
LPSAFEARRAY read_sa()
{
assert(size() <= SIZE_MAX);
_Assume_(size() <= SIZE_MAX);
size_t length = static_cast<size_t>(size());
std::unique_ptr<SAFEARRAY, SafeArrayDestroy_delete> sa(SafeArrayCreateVector(VT_UI1, 0, (ULONG)length));
if (!sa) _Unlikely_
@ -1263,7 +1262,7 @@ namespace stdex
virtual _Success_(return != 0 || length == 0) size_t read(
_Out_writes_bytes_to_opt_(length, return) void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
for (size_t to_read = length;;) {
uint8_t* ptr; size_t num_read;
std::tie(ptr, num_read) = m_ring.front();
@ -1329,7 +1328,7 @@ namespace stdex
virtual _Success_(return != 0) size_t write(
_In_reads_bytes_opt_(length) const void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
for (size_t to_write = length;;) {
uint8_t* ptr; size_t num_write;
std::tie(ptr, num_write) = m_ring.back();
@ -1415,7 +1414,7 @@ namespace stdex
virtual _Success_(return != 0 || length == 0) size_t read(
_Out_writes_bytes_to_opt_(length, return) void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
for (size_t to_read = length;;) {
size_t buffer_size = m_read_buffer.tail - m_read_buffer.head;
if (to_read <= buffer_size) {
@ -1451,7 +1450,7 @@ namespace stdex
virtual _Success_(return != 0) size_t write(
_In_reads_bytes_opt_(length) const void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
if (!length) _Unlikely_ {
// Pass null writes (zero-byte length). Null write operations have special meaning with with Windows pipes.
flush_write();
@ -1713,7 +1712,7 @@ namespace stdex
virtual _Success_(return != 0 || length == 0) size_t read(
_Out_writes_bytes_to_opt_(length, return) void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
if (m_region.contains(m_offset)) {
size_t num_read = m_source.read(data, static_cast<size_t>(std::min<fpos_t>(length, m_region.end - m_offset)));
m_state = m_source.state();
@ -1727,7 +1726,7 @@ namespace stdex
virtual _Success_(return != 0) size_t write(
_In_reads_bytes_opt_(length) const void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
if (m_region.contains(m_offset)) {
size_t num_written = m_source.write(data, static_cast<size_t>(std::min<fpos_t>(length, m_region.end - m_offset)));
m_state = m_source.state();
@ -1871,7 +1870,7 @@ namespace stdex
virtual _Success_(return != 0 || length == 0) size_t read(
_Out_writes_bytes_to_opt_(length, return) void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
#if SET_FILE_OP_TIMES
m_atime = time_point::now();
#endif
@ -1933,7 +1932,7 @@ namespace stdex
virtual _Success_(return != 0) size_t write(
_In_reads_bytes_opt_(length) const void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
#if SET_FILE_OP_TIMES
m_atime = m_mtime = time_point::now();
#endif
@ -2136,7 +2135,7 @@ namespace stdex
void load_cache(_In_ fpos_t start)
{
assert(m_cache.status != cache_t::cache_t::status_t::dirty);
_Assume_(m_cache.status != cache_t::cache_t::status_t::dirty);
start -= start % m_cache.capacity; // Align to cache block size.
m_source->seek(m_cache.region.start = start);
if (m_source->ok()) {
@ -2150,7 +2149,7 @@ namespace stdex
void write_cache()
{
assert(m_cache.status == cache_t::cache_t::status_t::dirty);
_Assume_(m_cache.status == cache_t::cache_t::status_t::dirty);
m_source->seek(m_cache.region.start);
m_source->write(m_cache.data, static_cast<size_t>(m_cache.region.size()));
m_state = m_source->state();
@ -2201,7 +2200,7 @@ namespace stdex
virtual _Success_(return != 0 || length == 0) size_t read(
_Out_writes_bytes_to_opt_(length, return) void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
// Windows Server 2003 and Windows XP: Pipe write operations across a network are limited in size per write.
// The amount varies per platform. For x86 platforms it's 63.97 MB. For x64 platforms it's 31.97 MB. For Itanium
// it's 63.95 MB. For more information regarding pipes, see the Remarks section.
@ -2403,7 +2402,7 @@ namespace stdex
virtual _Success_(return != 0 || length == 0) size_t read(
_Out_writes_bytes_to_opt_(length, return) void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
constexpr int block_size = 0x10000000;
for (size_t to_read = length;;) {
int num_read = recv(m_h, reinterpret_cast<char*>(data), static_cast<int>(std::min<size_t>(to_read, block_size)), 0);
@ -2427,7 +2426,7 @@ namespace stdex
virtual _Success_(return != 0) size_t write(
_In_reads_bytes_opt_(length) const void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
constexpr int block_size = 0x10000000;
for (size_t to_write = length;;) {
int num_written = send(m_h, reinterpret_cast<const char*>(data), static_cast<int>(std::min<size_t>(to_write, block_size)), 0);
@ -2477,7 +2476,7 @@ namespace stdex
virtual _Success_(return != 0 || length == 0) size_t read(
_Out_writes_bytes_to_opt_(length, return) void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
for (size_t to_read = length;;) {
HRESULT hr;
ULONG num_read = 0;
@ -2503,7 +2502,7 @@ namespace stdex
virtual _Success_(return != 0) size_t write(
_In_reads_bytes_opt_(length) const void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
for (size_t to_write = length;;) {
HRESULT hr;
ULONG num_written = 0;
@ -2555,7 +2554,7 @@ namespace stdex
virtual _Success_(return != 0 || length == 0) size_t read(
_Out_writes_bytes_to_opt_(length, return) void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
if (!m_request) _Unlikely_ {
m_state = state_t::fail;
return 0;
@ -2573,8 +2572,8 @@ namespace stdex
m_state = to_read < length ? state_t::ok : state_t::fail;
return length - to_read;
}
assert(V_VT(&var_amount) == VT_I4);
assert(V_VT(&var_data) == (VT_ARRAY | VT_UI1));
_Assume_(V_VT(&var_amount) == VT_I4);
_Assume_(V_VT(&var_data) == (VT_ARRAY | VT_UI1));
std::unique_ptr<SAFEARRAY, SafeArrayDestroy_delete> sa(V_ARRAY(&var_data));
if (!V_I4(&var_amount)) _Unlikely_ {
m_state = to_read < length || !length ? state_t::ok : state_t::eof;
@ -2978,7 +2977,7 @@ namespace stdex
virtual void set_ctime(time_point date)
{
assert(m_h != invalid_handle);
_Assume_(m_h != invalid_handle);
#ifdef _WIN32
FILETIME ft;
tp2ft(date, ft);
@ -2992,7 +2991,7 @@ namespace stdex
virtual void set_atime(time_point date)
{
assert(m_h != invalid_handle);
_Assume_(m_h != invalid_handle);
#ifdef _WIN32
FILETIME ft;
tp2ft(date, ft);
@ -3225,8 +3224,8 @@ namespace stdex
m_reserved(reserved),
m_manage(manage)
{
assert(data || !size);
assert(reserved >= size);
_Assume_(data || !size);
_Assume_(reserved >= size);
#if SET_FILE_OP_TIMES
m_ctime = m_atime = m_mtime = time_point::now();
#endif
@ -3387,7 +3386,7 @@ namespace stdex
virtual _Success_(return != 0 || length == 0) size_t read(
_Out_writes_bytes_to_opt_(length, return) void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
#if SET_FILE_OP_TIMES
m_atime = time_point::now();
#endif
@ -3497,7 +3496,7 @@ namespace stdex
virtual _Success_(return != 0) size_t write(
_In_reads_bytes_opt_(length) const void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
#if SET_FILE_OP_TIMES
m_atime = m_mtime = time_point::now();
#endif
@ -3804,7 +3803,7 @@ namespace stdex
protected:
///
/// Writes data to specified file location
/// This does not move file pointer nor update file size. It checks for reserved space assert-only (in Debug builds). Use with caution!
/// This does not move file pointer nor update file size. It checks for reserved space _Assume_-only (in Debug builds). Use with caution!
///
/// \param[in] offset Offset in file where to write data
/// \param[in] data Data to write
@ -3815,7 +3814,7 @@ namespace stdex
#if SET_FILE_OP_TIMES
m_atime = m_mtime = time_point::now();
#endif
assert(offset + sizeof(T) < m_size);
_Assume_(offset + sizeof(T) < m_size);
(*reinterpret_cast<T*>(m_data + offset)) = HE2LE(data);
}
@ -3837,7 +3836,7 @@ namespace stdex
///
/// Reads data from specified file location
/// This does not move file pointer. It checks for data size assert-only (in Debug builds). Use with caution!
/// This does not move file pointer. It checks for data size _Assume_-only (in Debug builds). Use with caution!
///
/// \param[in] offset Offset in file where to write data
/// \param[in] data Data to write
@ -3846,7 +3845,7 @@ namespace stdex
template <class T>
inline void get(_In_ fpos_t offset, _Out_ T & data)
{
assert(offset + sizeof(T) < m_size);
_Assume_(offset + sizeof(T) < m_size);
data = LE2HE(*(T*)(m_data + offset));
#if SET_FILE_OP_TIMES
m_atime = time_point::now();
@ -3941,7 +3940,7 @@ namespace stdex
virtual _Success_(return != 0 || length == 0) size_t read(
_Out_writes_bytes_to_opt_(length, return) void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
for (size_t to_read = length;;) {
if (!m_head) _Unlikely_ {
m_state = to_read < length || !length ? state_t::ok : state_t::eof;
@ -3969,7 +3968,7 @@ namespace stdex
virtual _Success_(return != 0) size_t write(
_In_reads_bytes_opt_(length) const void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
try {
std::unique_ptr<node_t> n(reinterpret_cast<node_t*>(new uint8_t[sizeof(node_t) + length]));
n->next = nullptr;
@ -4029,13 +4028,13 @@ namespace stdex
virtual _Success_(return != 0 || length == 0) size_t read(
_Out_writes_bytes_to_opt_(length, return) void* data, _In_ size_t length)
{
assert(data || !length);
_Assume_(data || !length);
if (m_files.empty()) {
m_state = state_t::fail;
return 0;
}
size_t result = m_files[0]->read(data, length);
_Analysis_assume_(result <= length);
_Assume_(result <= length);
m_state = m_files[0]->state();
if (length > m_tmp.size())
m_tmp.resize(length);

View File

@ -6,7 +6,6 @@
#pragma once
#include "compat.hpp"
#include <assert.h>
#include <ctype.h>
#include <locale.h>
#include <stdarg.h>
@ -127,7 +126,7 @@ namespace stdex
///
inline char32_t surrogate_pair_to_ucs4(_In_reads_(2) const utf16_t* str)
{
assert(is_surrogate_pair(str));
_Assume_(is_surrogate_pair(str));
return
((char32_t)(str[0] - 0xd800) << 10) +
(char32_t)(str[1] - 0xdc00) +
@ -141,7 +140,7 @@ namespace stdex
///
inline void ucs4_to_surrogate_pair(_Out_writes_(2) utf16_t* str, _In_ char32_t chr)
{
assert(chr >= 0x10000);
_Assume_(chr >= 0x10000);
chr -= 0x10000;
str[0] = 0xd800 + (char32_t)((chr >> 10) & 0x3ff);
str[1] = 0xdc00 + (char32_t)(chr & 0x3ff);
@ -181,7 +180,7 @@ namespace stdex
template <class T>
inline size_t islbreak(_In_reads_or_z_opt_(count) const T* chr, _In_ size_t count)
{
_Analysis_assume_(chr || !count);
_Assume_(chr || !count);
if (count >= 2 && ((chr[0] == '\r' && chr[1] == '\n') || (chr[0] == '\n' && chr[1] == '\r')))
return 2;
if (count > 1 && (chr[0] == '\n' || chr[0] == '\r'))
@ -197,7 +196,7 @@ namespace stdex
///
inline size_t glyphlen(_In_reads_or_z_opt_(count) const wchar_t* glyph, _In_ size_t count)
{
_Analysis_assume_(glyph || !count);
_Assume_(glyph || !count);
if (count) {
#ifdef _WIN32
size_t i = count < 2 || !is_surrogate_pair(glyph) ? 1 : 2;
@ -220,7 +219,7 @@ namespace stdex
template <class T>
inline size_t strlen(_In_z_ const T* str)
{
assert(str);
_Assume_(str);
size_t i;
for (i = 0; str[i]; ++i);
return i;
@ -237,7 +236,7 @@ namespace stdex
template <class T>
inline size_t strnlen(_In_reads_or_z_opt_(count) const T* str, _In_ size_t count)
{
assert(str || !count);
_Assume_(str || !count);
size_t i;
for (i = 0; i < count && str[i]; ++i);
return i;
@ -256,7 +255,7 @@ namespace stdex
template <class T>
inline size_t strchr(_In_z_ const T* str, _In_ T chr)
{
assert(str);
_Assume_(str);
for (size_t i = 0; str[i]; ++i)
if (str[i] == chr) return i;
return npos;
@ -277,7 +276,7 @@ namespace stdex
_In_ size_t count,
_In_ T chr)
{
assert(str || !count);
_Assume_(str || !count);
for (size_t i = 0; i < count && str[i]; ++i)
if (str[i] == chr) return i;
return npos;
@ -298,7 +297,7 @@ namespace stdex
_In_ size_t count,
_In_ T chr)
{
assert(str || !count);
_Assume_(str || !count);
size_t z = npos;
for (size_t i = 0; i < count && str[i]; ++i)
if (str[i] == chr) z = i;
@ -321,7 +320,7 @@ namespace stdex
_In_ T chr,
_In_ const std::locale& locale)
{
assert(str || !count);
_Assume_(str || !count);
const auto& ctype = std::use_facet<std::ctype<T>>(locale);
chr = ctype.tolower(chr);
for (size_t i = 0; i < count && str[i]; ++i)
@ -345,7 +344,7 @@ namespace stdex
_In_ T chr,
_In_ const std::locale& locale)
{
assert(str || !count);
_Assume_(str || !count);
const auto& ctype = std::use_facet<std::ctype<T>>(locale);
chr = ctype.tolower(chr);
size_t z = npos;
@ -369,8 +368,8 @@ namespace stdex
_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);
_Assume_(str1 || !count1);
_Assume_(str2 || !count2);
size_t i; T1 a; T2 b;
for (i = 0; i < count1 && i < count2 && ((a = str1[i]) | (b = str2[i])); ++i) {
if (a > b) return +1;
@ -393,7 +392,7 @@ namespace stdex
template <class T1, class T2>
inline int strncmp(_In_reads_or_z_opt_(count) const T1* str1, _In_reads_or_z_opt_(count) const T2* str2, _In_ size_t count)
{
assert((str1 && str2) || !count);
_Assume_((str1 && str2) || !count);
size_t i; T1 a; T2 b;
for (i = 0; i < count && ((a = str1[i]) | (b = str2[i])); ++i) {
if (a > b) return +1;
@ -420,8 +419,8 @@ namespace stdex
_In_reads_or_z_opt_(count2) const T* str2, _In_ size_t count2,
_In_ const std::locale& locale)
{
assert(str1 || !count1);
assert(str2 || !count2);
_Assume_(str1 || !count1);
_Assume_(str2 || !count2);
auto& collate = std::use_facet<std::collate<T>>(locale);
return collate.compare(str1, str1 + count1, str2, str2 + count2);
}
@ -437,8 +436,8 @@ namespace stdex
template <class T1, class T2>
inline int stricmp(_In_z_ const T1* str1, _In_z_ const T2* str2, _In_ const std::locale& locale)
{
assert(str1);
assert(str2);
_Assume_(str1);
_Assume_(str2);
size_t i; T1 a; T2 b;
const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
@ -463,8 +462,8 @@ namespace stdex
template <class T1, class T2>
inline int strnicmp(_In_reads_or_z_opt_(count) const T1* str1, _In_reads_or_z_opt_(count) const T2* str2, _In_ size_t count, _In_ const std::locale& locale)
{
assert(str1 || !count);
assert(str2 || !count);
_Assume_(str1 || !count);
_Assume_(str2 || !count);
size_t i; T1 a; T2 b;
const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
@ -493,8 +492,8 @@ namespace stdex
_In_reads_or_z_opt_(count2) const T2* str2, _In_ size_t count2,
_In_ const std::locale& locale)
{
assert(str1 || !count1);
assert(str2 || !count2);
_Assume_(str1 || !count1);
_Assume_(str2 || !count2);
size_t i; T1 a; T2 b;
const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
@ -520,8 +519,8 @@ namespace stdex
_In_z_ const T1* str,
_In_z_ const T2* sample)
{
assert(str);
assert(sample);
_Assume_(str);
_Assume_(sample);
for (size_t offset = 0;; ++offset) {
for (size_t i = offset, j = 0;; ++i, ++j) {
if (!sample[j])
@ -549,8 +548,8 @@ namespace stdex
_In_ size_t count,
_In_z_ const T2* sample)
{
assert(str || !count);
assert(sample);
_Assume_(str || !count);
_Assume_(sample);
for (size_t offset = 0;; ++offset) {
for (size_t i = offset, j = 0;; ++i, ++j) {
if (!sample[j])
@ -577,8 +576,8 @@ namespace stdex
_In_z_ const T2* sample,
_In_ const std::locale& locale)
{
assert(str);
assert(sample);
_Assume_(str);
_Assume_(sample);
const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
for (size_t offset = 0;; ++offset) {
@ -609,8 +608,8 @@ namespace stdex
_In_z_ const T2* sample,
_In_ const std::locale& locale)
{
assert(str || !count);
assert(sample);
_Assume_(str || !count);
_Assume_(sample);
const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
for (size_t offset = 0;; ++offset) {
@ -638,7 +637,7 @@ namespace stdex
_Out_writes_z_(_String_length_(src) + 1) T1* dst,
_In_z_ const T2* src)
{
assert(dst && src);
_Assume_(dst && src);
for (size_t i = 0; ; ++i) {
if ((dst[i] = src[i]) == 0)
return i;
@ -659,7 +658,7 @@ namespace stdex
_Out_writes_(count) _Post_maybez_ T1* dst,
_In_reads_or_z_opt_(count) const T2* src, _In_ size_t count)
{
assert(dst && src || !count);
_Assume_(dst && src || !count);
for (size_t i = 0; ; ++i) {
if (i >= count)
return i;
@ -683,8 +682,8 @@ namespace stdex
_Out_writes_(count_dst) _Post_maybez_ T1* dst, _In_ size_t count_dst,
_In_reads_or_z_opt_(count_src) const T2* src, _In_ size_t count_src)
{
assert(dst || !count_dst);
assert(src || !count_src);
_Assume_(dst || !count_dst);
_Assume_(src || !count_src);
for (size_t i = 0; ; ++i)
{
if (i >= count_dst)
@ -711,7 +710,7 @@ namespace stdex
_In_z_ _Out_writes_z_(_String_length_(dst) + _String_length_(src) + 1) T1* dst,
_In_z_ const T2* src)
{
assert(dst && src);
_Assume_(dst && src);
for (size_t i = 0, j = stdex::strlen<T1>(dst); ; ++i, ++j) {
if ((dst[j] = src[i]) == 0)
return j;
@ -732,7 +731,7 @@ namespace stdex
_Out_writes_(count) _Post_maybez_ T1* dst,
_In_reads_or_z_opt_(count) const T2* src, _In_ size_t count)
{
assert(dst && src || !count);
_Assume_(dst && src || !count);
for (size_t i = 0, j = stdex::strlen<T1>(dst); ; ++i, ++j) {
if (i >= count)
return j;
@ -756,8 +755,8 @@ namespace stdex
_Out_writes_(count_dst) _Post_maybez_ T1* dst, _In_ size_t count_dst,
_In_reads_or_z_opt_(count_src) const T2* src, _In_ size_t count_src)
{
assert(dst || !count_dst);
assert(src || !count_src);
_Assume_(dst || !count_dst);
_Assume_(src || !count_src);
for (size_t i = 0, j = stdex::strnlen<T1>(dst, count_dst); ; ++i, ++j)
{
if (j >= count_dst)
@ -825,8 +824,8 @@ namespace stdex
template <class T>
inline size_t crlf2nl(_Out_writes_z_(strlen(src)) T* dst, _In_z_ const T* src)
{
assert(dst);
assert(src);
_Assume_(dst);
_Assume_(src);
size_t i, j;
for (i = j = 0; src[j];) {
if (src[j] != '\r' || src[j + 1] != '\n')
@ -848,8 +847,8 @@ namespace stdex
_In_ int radix,
_Out_ uint8_t& flags)
{
assert(str || !count);
assert(radix == 0 || 2 <= radix && radix <= 36);
_Assume_(str || !count);
_Assume_(radix == 0 || 2 <= radix && radix <= 36);
size_t i = 0;
T_bin value = 0, digit,
@ -1405,7 +1404,7 @@ namespace stdex
template<class T>
inline void strlwr(_Inout_z_ T* str, _In_ const std::locale& locale)
{
assert(str);
_Assume_(str);
const auto& ctype = std::use_facet<std::ctype<T>>(locale);
for (size_t i = 0; str[i]; ++i)
str[i] = ctype.tolower(str[i]);
@ -1422,7 +1421,7 @@ namespace stdex
template<class T>
inline void strlwr(_Inout_updates_z_(count) T* str, _In_ size_t count, _In_ const std::locale& locale)
{
assert(str || !count);
_Assume_(str || !count);
const auto& ctype = std::use_facet<std::ctype<T>>(locale);
for (size_t i = 0; i < count && str[i]; ++i)
str[i] = ctype.tolower(str[i]);
@ -1438,7 +1437,7 @@ namespace stdex
template<class T>
inline void strupr(_Inout_z_ T* str, _In_ const std::locale& locale)
{
assert(str);
_Assume_(str);
const auto& ctype = std::use_facet<std::ctype<T>>(locale);
for (size_t i = 0; str[i]; ++i)
str[i] = ctype.toupper(str[i]);
@ -1455,7 +1454,7 @@ namespace stdex
template<class T>
inline void strupr(_Inout_updates_z_(count) T* str, _In_ size_t count, _In_ const std::locale& locale)
{
assert(str || !count);
_Assume_(str || !count);
const auto& ctype = std::use_facet<std::ctype<T>>(locale);
for (size_t i = 0; i < count && str[i]; ++i)
str[i] = ctype.toupper(str[i]);

View File

@ -20,7 +20,6 @@
#include <unistd.h>
#endif
#include "compat.hpp"
#include <assert.h>
#include <regex>
#include <stdexcept>
#include <string>
@ -331,7 +330,7 @@ namespace stdex
#ifdef _WIN32
HMODULE kernel32_handle;
kernel32_handle = LoadLibrary(_T("kernel32.dll"));
_Analysis_assume_(kernel32_handle);
_Assume_(kernel32_handle);
BOOL (WINAPI* IsWow64Process2)(HANDLE hProcess, USHORT* pProcessMachine, USHORT* pNativeMachine);
*reinterpret_cast<FARPROC*>(&IsWow64Process2) = GetProcAddress(kernel32_handle, "IsWow64Process2");
HANDLE process = GetCurrentProcess();

View File

@ -9,7 +9,6 @@
#include "endian.hpp"
#include "math.hpp"
#include "system.hpp"
#include <assert.h>
#include <stdint.h>
#ifndef _WIN32
#include <iconv.h>
@ -104,7 +103,7 @@ namespace stdex
_Inout_ std::basic_string<T_to, _Traits_to, _Alloc_to> &dst,
_In_reads_or_z_opt_(count_src) const T_from* src, _In_ size_t count_src)
{
assert(src || !count_src);
_Assume_(src || !count_src);
count_src = stdex::strnlen(src, count_src);
if (!count_src) _Unlikely_
return;
@ -114,7 +113,7 @@ namespace stdex
constexpr DWORD dwFlagsWCMB = 0;
constexpr LPCCH lpDefaultChar = NULL;
_Analysis_assume_(src);
_Assume_(src);
if (m_from_wincp == m_to_wincp) _Unlikely_{
dst.append(reinterpret_cast<const T_to*>(src), count_src);
return;
@ -122,7 +121,7 @@ namespace stdex
#pragma warning(suppress: 4127)
if _Constexpr_ (sizeof(T_from) == sizeof(char) && sizeof(T_to) == sizeof(wchar_t)) {
assert(count_src < INT_MAX || count_src == SIZE_MAX);
_Assume_(count_src < INT_MAX || count_src == SIZE_MAX);
// Try to convert to stack buffer first.
WCHAR szStackBuffer[1024 / sizeof(WCHAR)];
@ -146,7 +145,7 @@ namespace stdex
#pragma warning(suppress: 4127)
if _Constexpr_ (sizeof(T_from) == sizeof(wchar_t) && sizeof(T_to) == sizeof(char)) {
assert(count_src < INT_MAX || count_src == SIZE_MAX);
_Assume_(count_src < INT_MAX || count_src == SIZE_MAX);
// Try to convert to stack buffer first.
CHAR szStackBuffer[1024 / sizeof(CHAR)];
@ -170,7 +169,7 @@ namespace stdex
#pragma warning(suppress: 4127)
if _Constexpr_ (sizeof(T_from) == sizeof(char) && sizeof(T_to) == sizeof(char)) {
assert(count_src < INT_MAX || count_src == SIZE_MAX);
_Assume_(count_src < INT_MAX || count_src == SIZE_MAX);
// Try to convert to stack buffer first.
WCHAR szStackBufferMBWC[512 / sizeof(WCHAR)];
@ -179,7 +178,7 @@ namespace stdex
if (cch) {
// Append from stack.
size_t count_inter = count_src != SIZE_MAX ? wcsnlen(szStackBufferMBWC, cch) : static_cast<size_t>(cch) - 1;
assert(count_inter < INT_MAX);
_Assume_(count_inter < INT_MAX);
// Try to convert to stack buffer first.
CHAR szStackBufferWCMB[512 / sizeof(CHAR)];