Coverage Report

Created: 2025-08-26 06:10

/src/upx/src/util/xspan_impl.h
Line
Count
Source (jump to first uncovered line)
1
/* xspan -- a minimally invasive checked memory smart pointer
2
3
   This file is part of the UPX executable compressor.
4
5
   Copyright (C) 1996-2025 Markus Franz Xaver Johannes Oberhumer
6
   All Rights Reserved.
7
8
   UPX and the UCL library are free software; you can redistribute them
9
   and/or modify them under the terms of the GNU General Public License as
10
   published by the Free Software Foundation; either version 2 of
11
   the License, or (at your option) any later version.
12
13
   This program is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
18
   You should have received a copy of the GNU General Public License
19
   along with this program; see the file COPYING.
20
   If not, write to the Free Software Foundation, Inc.,
21
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23
   Markus F.X.J. Oberhumer
24
   <markus@oberhumer.com>
25
 */
26
27
#pragma once
28
29
#if WITH_XSPAN
30
31
// namespace
32
#if 1
33
#define XSPAN_NAMESPACE_NAME  XSpan
34
#define XSPAN_NAMESPACE_BEGIN namespace XSPAN_NAMESPACE_NAME {
35
#define XSPAN_NAMESPACE_END   }
36
#define XSPAN_NS(x)           XSPAN_NAMESPACE_NAME ::x
37
#else
38
#define XSPAN_NAMESPACE_BEGIN /*empty*/
39
#define XSPAN_NAMESPACE_END   /*empty*/
40
#define XSPAN_NS(x)           ::x
41
#endif
42
43
XSPAN_NAMESPACE_BEGIN
44
45
// HINT: set env-var "UPX_DEBUG_DOCTEST_DISABLE=1" for improved debugging experience
46
noreturn void xspan_fail_nullptr(void) may_throw;
47
noreturn void xspan_fail_nullbase(void) may_throw;
48
noreturn void xspan_fail_not_same_base(void) may_throw;
49
noreturn void xspan_fail_range_nullptr(void) may_throw;
50
noreturn void xspan_fail_range_nullbase(void) may_throw;
51
noreturn void xspan_fail_range_range(void) may_throw;
52
void xspan_check_range(const void *ptr, const void *base, ptrdiff_t size_in_bytes) may_throw;
53
54
// help constructor to distinguish between number of elements and bytes
55
struct XSpanCount final {
56
0
    explicit forceinline_constexpr XSpanCount(size_t n) noexcept : count(n) {}
57
    const size_t count; // public
58
};
59
struct XSpanSizeInBytes final {
60
176k
    explicit forceinline_constexpr XSpanSizeInBytes(size_t bytes) noexcept : size_in_bytes(bytes) {}
61
    const size_t size_in_bytes; // public
62
};
63
64
template <class T>
65
struct TypeForSizeOf {
66
    typedef T type;
67
};
68
template <>
69
struct TypeForSizeOf<void> {
70
    typedef char type;
71
};
72
template <>
73
struct TypeForSizeOf<const void> {
74
    typedef const char type;
75
};
76
77
template <class T>
78
struct ValueForSizeOf {
79
    static const size_t value = sizeof(typename TypeForSizeOf<T>::type);
80
};
81
82
ACC_COMPILE_TIME_ASSERT_HEADER(ValueForSizeOf<char>::value == 1)
83
ACC_COMPILE_TIME_ASSERT_HEADER(ValueForSizeOf<const char>::value == 1)
84
ACC_COMPILE_TIME_ASSERT_HEADER(ValueForSizeOf<void>::value == 1)
85
ACC_COMPILE_TIME_ASSERT_HEADER(ValueForSizeOf<const void>::value == 1)
86
ACC_COMPILE_TIME_ASSERT_HEADER(ValueForSizeOf<int>::value == 4)
87
88
#ifndef xspan_mem_size_impl
89
template <class T>
90
8.15M
static inline size_t xspan_mem_size_impl(size_t n) {
91
8.15M
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
8.15M
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
8.15M
}
dt_xspan.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Line
Count
Source
90
6.23M
static inline size_t xspan_mem_size_impl(size_t n) {
91
6.23M
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
6.23M
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
6.23M
}
dt_xspan.cpp:unsigned long XSpan::xspan_mem_size_impl<char const>(unsigned long)
Line
Count
Source
90
92.0k
static inline size_t xspan_mem_size_impl(size_t n) {
91
92.0k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
92.0k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
92.0k
}
dt_xspan.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned short>(unsigned long)
Line
Count
Source
90
138k
static inline size_t xspan_mem_size_impl(size_t n) {
91
138k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
138k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
138k
}
lefile.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Line
Count
Source
90
1.94k
static inline size_t xspan_mem_size_impl(size_t n) {
91
1.94k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
1.94k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
1.94k
}
lefile.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char>(unsigned long)
Line
Count
Source
90
3
static inline size_t xspan_mem_size_impl(size_t n) {
91
3
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
3
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
3
}
p_com.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Line
Count
Source
90
120k
static inline size_t xspan_mem_size_impl(size_t n) {
91
120k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
120k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
120k
}
p_djgpp2.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Line
Count
Source
90
1.49k
static inline size_t xspan_mem_size_impl(size_t n) {
91
1.49k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
1.49k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
1.49k
}
p_exe.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char>(unsigned long)
Line
Count
Source
90
103k
static inline size_t xspan_mem_size_impl(size_t n) {
91
103k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
103k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
103k
}
p_exe.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char const>(unsigned long)
Line
Count
Source
90
606k
static inline size_t xspan_mem_size_impl(size_t n) {
91
606k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
606k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
606k
}
p_exe.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Line
Count
Source
90
51.5k
static inline size_t xspan_mem_size_impl(size_t n) {
91
51.5k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
51.5k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
51.5k
}
Unexecuted instantiation: p_lx_elf.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Unexecuted instantiation: p_lx_interp.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Unexecuted instantiation: p_mach.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Unexecuted instantiation: p_ps1.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Unexecuted instantiation: p_sys.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Unexecuted instantiation: p_tmt.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Unexecuted instantiation: p_tmt.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char>(unsigned long)
Unexecuted instantiation: p_tmt.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char const>(unsigned long)
Unexecuted instantiation: p_tos.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Unexecuted instantiation: p_unix.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Unexecuted instantiation: p_vmlinx.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Unexecuted instantiation: p_vmlinz.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Unexecuted instantiation: p_wcle.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Unexecuted instantiation: p_wcle.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char>(unsigned long)
Unexecuted instantiation: p_wcle.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char const>(unsigned long)
Unexecuted instantiation: packer.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Unexecuted instantiation: packer.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char>(unsigned long)
packer.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char const>(unsigned long)
Line
Count
Source
90
61.2k
static inline size_t xspan_mem_size_impl(size_t n) {
91
61.2k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
61.2k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
61.2k
}
packer_r.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char>(unsigned long)
Line
Count
Source
90
102k
static inline size_t xspan_mem_size_impl(size_t n) {
91
102k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
102k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
102k
}
packer_r.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char const>(unsigned long)
Line
Count
Source
90
4.18k
static inline size_t xspan_mem_size_impl(size_t n) {
91
4.18k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
4.18k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
4.18k
}
packer_r.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Line
Count
Source
90
5
static inline size_t xspan_mem_size_impl(size_t n) {
91
5
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
5
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
5
}
packer_r.cpp:unsigned long XSpan::xspan_mem_size_impl<LE32>(unsigned long)
Line
Count
Source
90
51.2k
static inline size_t xspan_mem_size_impl(size_t n) {
91
51.2k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
51.2k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
51.2k
}
packhead.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char const>(unsigned long)
Line
Count
Source
90
285k
static inline size_t xspan_mem_size_impl(size_t n) {
91
285k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
285k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
285k
}
Unexecuted instantiation: packhead.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char>(unsigned long)
pefile.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char>(unsigned long)
Line
Count
Source
90
169k
static inline size_t xspan_mem_size_impl(size_t n) {
91
169k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
169k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
169k
}
pefile.cpp:unsigned long XSpan::xspan_mem_size_impl<unsigned char const>(unsigned long)
Line
Count
Source
90
66.0k
static inline size_t xspan_mem_size_impl(size_t n) {
91
66.0k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
66.0k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
66.0k
}
pefile.cpp:unsigned long XSpan::xspan_mem_size_impl<LE16>(unsigned long)
Line
Count
Source
90
51.2k
static inline size_t xspan_mem_size_impl(size_t n) {
91
51.2k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
51.2k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
51.2k
}
pefile.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
Line
Count
Source
90
957
static inline size_t xspan_mem_size_impl(size_t n) {
91
957
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
957
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
957
}
Unexecuted instantiation: pefile.cpp:unsigned long XSpan::xspan_mem_size_impl<char const>(unsigned long)
pefile.cpp:unsigned long XSpan::xspan_mem_size_impl<PeFile::pe_section_t>(unsigned long)
Line
Count
Source
90
2.61k
static inline size_t xspan_mem_size_impl(size_t n) {
91
2.61k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
2.61k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
2.61k
}
Unexecuted instantiation: pefile.cpp:unsigned long XSpan::xspan_mem_size_impl<LE32 const>(unsigned long)
pefile.cpp:unsigned long XSpan::xspan_mem_size_impl<LE32>(unsigned long)
Line
Count
Source
90
5.70k
static inline size_t xspan_mem_size_impl(size_t n) {
91
5.70k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
5.70k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
5.70k
}
pefile.cpp:unsigned long XSpan::xspan_mem_size_impl<PeFile::import_desc>(unsigned long)
Line
Count
Source
90
185
static inline size_t xspan_mem_size_impl(size_t n) {
91
185
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
185
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
185
}
pefile.cpp:unsigned long XSpan::xspan_mem_size_impl<LE64>(unsigned long)
Line
Count
Source
90
1.21k
static inline size_t xspan_mem_size_impl(size_t n) {
91
1.21k
#ifdef UPX_VERSION_HEX
92
    // check for overflow and sane limits
93
1.21k
    return mem_size(sizeof(T), n);
94
#else
95
    return sizeof(T) * n;
96
#endif
97
1.21k
}
Unexecuted instantiation: pefile.cpp:unsigned long XSpan::xspan_mem_size_impl<LE64 const>(unsigned long)
Unexecuted instantiation: work.cpp:unsigned long XSpan::xspan_mem_size_impl<char>(unsigned long)
98
#endif
99
100
template <class T>
101
8.15M
static inline size_t xspan_mem_size(size_t n) {
102
8.15M
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
8.15M
}
dt_xspan.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Line
Count
Source
101
6.23M
static inline size_t xspan_mem_size(size_t n) {
102
6.23M
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
6.23M
}
dt_xspan.cpp:unsigned long XSpan::xspan_mem_size<char const>(unsigned long)
Line
Count
Source
101
92.0k
static inline size_t xspan_mem_size(size_t n) {
102
92.0k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
92.0k
}
dt_xspan.cpp:unsigned long XSpan::xspan_mem_size<unsigned short>(unsigned long)
Line
Count
Source
101
138k
static inline size_t xspan_mem_size(size_t n) {
102
138k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
138k
}
lefile.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Line
Count
Source
101
1.94k
static inline size_t xspan_mem_size(size_t n) {
102
1.94k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
1.94k
}
lefile.cpp:unsigned long XSpan::xspan_mem_size<unsigned char>(unsigned long)
Line
Count
Source
101
3
static inline size_t xspan_mem_size(size_t n) {
102
3
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
3
}
p_com.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Line
Count
Source
101
120k
static inline size_t xspan_mem_size(size_t n) {
102
120k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
120k
}
p_djgpp2.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Line
Count
Source
101
1.49k
static inline size_t xspan_mem_size(size_t n) {
102
1.49k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
1.49k
}
p_exe.cpp:unsigned long XSpan::xspan_mem_size<unsigned char>(unsigned long)
Line
Count
Source
101
103k
static inline size_t xspan_mem_size(size_t n) {
102
103k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
103k
}
p_exe.cpp:unsigned long XSpan::xspan_mem_size<unsigned char const>(unsigned long)
Line
Count
Source
101
606k
static inline size_t xspan_mem_size(size_t n) {
102
606k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
606k
}
p_exe.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Line
Count
Source
101
51.5k
static inline size_t xspan_mem_size(size_t n) {
102
51.5k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
51.5k
}
Unexecuted instantiation: p_lx_elf.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Unexecuted instantiation: p_lx_interp.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Unexecuted instantiation: p_mach.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Unexecuted instantiation: p_ps1.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Unexecuted instantiation: p_sys.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Unexecuted instantiation: p_tmt.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Unexecuted instantiation: p_tmt.cpp:unsigned long XSpan::xspan_mem_size<unsigned char>(unsigned long)
Unexecuted instantiation: p_tmt.cpp:unsigned long XSpan::xspan_mem_size<unsigned char const>(unsigned long)
Unexecuted instantiation: p_tos.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Unexecuted instantiation: p_unix.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Unexecuted instantiation: p_vmlinx.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Unexecuted instantiation: p_vmlinz.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Unexecuted instantiation: p_wcle.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Unexecuted instantiation: p_wcle.cpp:unsigned long XSpan::xspan_mem_size<unsigned char>(unsigned long)
Unexecuted instantiation: p_wcle.cpp:unsigned long XSpan::xspan_mem_size<unsigned char const>(unsigned long)
Unexecuted instantiation: packer.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Unexecuted instantiation: packer.cpp:unsigned long XSpan::xspan_mem_size<unsigned char>(unsigned long)
packer.cpp:unsigned long XSpan::xspan_mem_size<unsigned char const>(unsigned long)
Line
Count
Source
101
61.2k
static inline size_t xspan_mem_size(size_t n) {
102
61.2k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
61.2k
}
packer_r.cpp:unsigned long XSpan::xspan_mem_size<unsigned char>(unsigned long)
Line
Count
Source
101
102k
static inline size_t xspan_mem_size(size_t n) {
102
102k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
102k
}
packer_r.cpp:unsigned long XSpan::xspan_mem_size<unsigned char const>(unsigned long)
Line
Count
Source
101
4.18k
static inline size_t xspan_mem_size(size_t n) {
102
4.18k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
4.18k
}
packer_r.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Line
Count
Source
101
5
static inline size_t xspan_mem_size(size_t n) {
102
5
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
5
}
packer_r.cpp:unsigned long XSpan::xspan_mem_size<LE32>(unsigned long)
Line
Count
Source
101
51.2k
static inline size_t xspan_mem_size(size_t n) {
102
51.2k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
51.2k
}
packhead.cpp:unsigned long XSpan::xspan_mem_size<unsigned char const>(unsigned long)
Line
Count
Source
101
285k
static inline size_t xspan_mem_size(size_t n) {
102
285k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
285k
}
Unexecuted instantiation: packhead.cpp:unsigned long XSpan::xspan_mem_size<unsigned char>(unsigned long)
pefile.cpp:unsigned long XSpan::xspan_mem_size<unsigned char>(unsigned long)
Line
Count
Source
101
169k
static inline size_t xspan_mem_size(size_t n) {
102
169k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
169k
}
pefile.cpp:unsigned long XSpan::xspan_mem_size<unsigned char const>(unsigned long)
Line
Count
Source
101
66.0k
static inline size_t xspan_mem_size(size_t n) {
102
66.0k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
66.0k
}
pefile.cpp:unsigned long XSpan::xspan_mem_size<LE16>(unsigned long)
Line
Count
Source
101
51.2k
static inline size_t xspan_mem_size(size_t n) {
102
51.2k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
51.2k
}
pefile.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
Line
Count
Source
101
957
static inline size_t xspan_mem_size(size_t n) {
102
957
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
957
}
Unexecuted instantiation: pefile.cpp:unsigned long XSpan::xspan_mem_size<char const>(unsigned long)
pefile.cpp:unsigned long XSpan::xspan_mem_size<PeFile::pe_section_t>(unsigned long)
Line
Count
Source
101
2.61k
static inline size_t xspan_mem_size(size_t n) {
102
2.61k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
2.61k
}
Unexecuted instantiation: pefile.cpp:unsigned long XSpan::xspan_mem_size<LE32 const>(unsigned long)
pefile.cpp:unsigned long XSpan::xspan_mem_size<LE32>(unsigned long)
Line
Count
Source
101
5.70k
static inline size_t xspan_mem_size(size_t n) {
102
5.70k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
5.70k
}
pefile.cpp:unsigned long XSpan::xspan_mem_size<PeFile::import_desc>(unsigned long)
Line
Count
Source
101
185
static inline size_t xspan_mem_size(size_t n) {
102
185
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
185
}
pefile.cpp:unsigned long XSpan::xspan_mem_size<LE64>(unsigned long)
Line
Count
Source
101
1.21k
static inline size_t xspan_mem_size(size_t n) {
102
1.21k
    return xspan_mem_size_impl<typename TypeForSizeOf<T>::type>(n);
103
1.21k
}
Unexecuted instantiation: pefile.cpp:unsigned long XSpan::xspan_mem_size<LE64 const>(unsigned long)
Unexecuted instantiation: work.cpp:unsigned long XSpan::xspan_mem_size<char>(unsigned long)
104
105
template <class T>
106
7.45M
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
7.45M
    if (n >= 0)
108
7.45M
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
7.45M
}
dt_xspan.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<char>(long)
Line
Count
Source
106
5.86M
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
5.86M
    if (n >= 0)
108
5.86M
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
5.86M
}
dt_xspan.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<unsigned short>(long)
Line
Count
Source
106
138k
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
138k
    if (n >= 0)
108
138k
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
138k
}
lefile.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<unsigned char>(long)
Line
Count
Source
106
3
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
3
    if (n >= 0)
108
3
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
3
}
p_exe.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<unsigned char>(long)
Line
Count
Source
106
103k
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
103k
    if (n >= 0)
108
103k
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
103k
}
p_exe.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<unsigned char const>(long)
Line
Count
Source
106
606k
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
606k
    if (n >= 0)
108
606k
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
606k
}
Unexecuted instantiation: p_tmt.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<unsigned char>(long)
Unexecuted instantiation: p_wcle.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<unsigned char>(long)
Unexecuted instantiation: p_wcle.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<unsigned char const>(long)
packer_r.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<unsigned char>(long)
Line
Count
Source
106
102k
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
102k
    if (n >= 0)
108
102k
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
102k
}
packer_r.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<unsigned char const>(long)
Line
Count
Source
106
4.18k
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
4.18k
    if (n >= 0)
108
4.18k
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
4.18k
}
packer_r.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<LE32>(long)
Line
Count
Source
106
51.2k
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
51.2k
    if (n >= 0)
108
51.2k
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
51.2k
}
packhead.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<unsigned char const>(long)
Line
Count
Source
106
285k
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
285k
    if (n >= 0)
108
285k
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
285k
}
Unexecuted instantiation: packhead.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<unsigned char>(long)
pefile.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<unsigned char>(long)
Line
Count
Source
106
169k
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
169k
    if (n >= 0)
108
169k
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
169k
}
pefile.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<unsigned char const>(long)
Line
Count
Source
106
65.9k
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
65.9k
    if (n >= 0)
108
65.9k
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
65.9k
}
pefile.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<LE16>(long)
Line
Count
Source
106
51.2k
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
51.2k
    if (n >= 0)
108
51.2k
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
51.2k
}
Unexecuted instantiation: pefile.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<char>(long)
Unexecuted instantiation: pefile.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<char const>(long)
pefile.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<PeFile::pe_section_t>(long)
Line
Count
Source
106
2.61k
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
2.61k
    if (n >= 0)
108
2.61k
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
2.61k
}
Unexecuted instantiation: pefile.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<LE32 const>(long)
pefile.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<LE32>(long)
Line
Count
Source
106
5.70k
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
5.70k
    if (n >= 0)
108
5.70k
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
5.70k
}
pefile.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<PeFile::import_desc>(long)
Line
Count
Source
106
185
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
185
    if (n >= 0)
108
185
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
185
}
pefile.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<LE64>(long)
Line
Count
Source
106
1.21k
static inline void xspan_mem_size_assert_ptrdiff(ptrdiff_t n) {
107
1.21k
    if (n >= 0)
108
1.21k
        (void) xspan_mem_size<T>((size_t) n);
109
0
    else
110
0
        (void) xspan_mem_size<T>((size_t) -n);
111
1.21k
}
Unexecuted instantiation: pefile.cpp:void XSpan::xspan_mem_size_assert_ptrdiff<LE64 const>(long)
112
113
#if __cplusplus >= 201103L && 0
114
// unfortunately doesn't work with some older versions of libstdc++
115
// (TODO later: we now require C++17, so this now probably works on all supported platforms)
116
template <class From, class To>
117
struct XSpan_is_convertible : public std::is_convertible<From *, To *> {};
118
#else
119
// manual implementation
120
121
namespace XSpan_detail {
122
// XSpan_void_to_T - helper for "void"
123
template <class T, class U>
124
struct XSpan_void_to_T {
125
    typedef U type;
126
};
127
template <class T>
128
struct XSpan_void_to_T<T, void> {
129
    typedef typename std::remove_const<T>::type type;
130
};
131
template <class T>
132
struct XSpan_void_to_T<T, const void> {
133
    typedef T type;
134
};
135
// XSpan_ptr_is_convertible
136
template <class From, class To>
137
struct XSpan_ptr_is_convertible : public std::false_type {};
138
template <class T>
139
struct XSpan_ptr_is_convertible<T, T> : public std::true_type {};
140
template <class T>
141
struct XSpan_ptr_is_convertible<T, const T> : public std::true_type {};
142
} // namespace XSpan_detail
143
144
template <class From, class To>
145
struct XSpan_is_convertible : public XSpan_detail::XSpan_ptr_is_convertible<
146
                                  From, typename XSpan_detail::XSpan_void_to_T<From, To>::type> {};
147
#endif
148
149
#if DEBUG
150
// need extra parenthesis because the C preprocessor does not understand C++ templates
151
// char => char
152
ACC_COMPILE_TIME_ASSERT_HEADER((XSpan_is_convertible<char, char>::value))
153
ACC_COMPILE_TIME_ASSERT_HEADER((XSpan_is_convertible<char, const char>::value))
154
ACC_COMPILE_TIME_ASSERT_HEADER((XSpan_is_convertible<const char, const char>::value))
155
ACC_COMPILE_TIME_ASSERT_HEADER((!XSpan_is_convertible<const char, char>::value))
156
// void => void
157
ACC_COMPILE_TIME_ASSERT_HEADER((XSpan_is_convertible<void, void>::value))
158
ACC_COMPILE_TIME_ASSERT_HEADER((XSpan_is_convertible<void, const void>::value))
159
ACC_COMPILE_TIME_ASSERT_HEADER((XSpan_is_convertible<const void, const void>::value))
160
ACC_COMPILE_TIME_ASSERT_HEADER((!XSpan_is_convertible<const void, void>::value))
161
// char => void
162
ACC_COMPILE_TIME_ASSERT_HEADER((XSpan_is_convertible<char, void>::value))
163
ACC_COMPILE_TIME_ASSERT_HEADER((XSpan_is_convertible<char, const void>::value))
164
ACC_COMPILE_TIME_ASSERT_HEADER((XSpan_is_convertible<const char, const void>::value))
165
ACC_COMPILE_TIME_ASSERT_HEADER((!XSpan_is_convertible<const char, void>::value))
166
// void => char
167
ACC_COMPILE_TIME_ASSERT_HEADER((!XSpan_is_convertible<void, char>::value))
168
ACC_COMPILE_TIME_ASSERT_HEADER((!XSpan_is_convertible<void, const char>::value))
169
ACC_COMPILE_TIME_ASSERT_HEADER((!XSpan_is_convertible<const void, const char>::value))
170
ACC_COMPILE_TIME_ASSERT_HEADER((!XSpan_is_convertible<const void, char>::value))
171
// char => int
172
ACC_COMPILE_TIME_ASSERT_HEADER((!XSpan_is_convertible<char, int>::value))
173
ACC_COMPILE_TIME_ASSERT_HEADER((!XSpan_is_convertible<char, const int>::value))
174
ACC_COMPILE_TIME_ASSERT_HEADER((!XSpan_is_convertible<const char, const int>::value))
175
ACC_COMPILE_TIME_ASSERT_HEADER((!XSpan_is_convertible<const char, int>::value))
176
#endif
177
178
/*************************************************************************
179
// PtrOrSpanOrNull
180
// PtrOrSpan
181
// Span
182
// Ptr
183
**************************************************************************/
184
185
// forward declarations
186
template <class T>
187
struct PtrOrSpanOrNull;
188
template <class T>
189
struct PtrOrSpan;
190
template <class T>
191
struct Span;
192
template <class T>
193
struct Ptr;
194
195
// XSpanInternalDummyArg: some type that is hard to match by accident
196
//   (this should result in efficient code and fully get optimized away)
197
#if 0
198
// too simple, can be matched by nullptr
199
class XSpanInternalDummyArgFake; // not implemented on purpose
200
typedef XSpanInternalDummyArgFake *XSpanInternalDummyArg;
201
#define XSpanInternalDummyArgInit nullptr
202
#elif __cplusplus >= 201103L && 1
203
// use an enum and a move constructor
204
struct XSpanInternalDummyArg final {
205
    enum DummyEnum {};
206
764k
    explicit forceinline_constexpr XSpanInternalDummyArg(DummyEnum &&) noexcept {}
207
};
208
#define XSpanInternalDummyArgInit                                                                  \
209
    (XSPAN_NS(XSpanInternalDummyArg)(XSPAN_NS(XSpanInternalDummyArg)::DummyEnum{}))
210
#else
211
// use a class with a private constructor
212
struct XSpanInternalDummyArg final {
213
    static forceinline_constexpr XSpanInternalDummyArg make() noexcept {
214
        return XSpanInternalDummyArg();
215
    }
216
private:
217
    explicit forceinline_constexpr XSpanInternalDummyArg() noexcept {}
218
};
219
#define XSpanInternalDummyArgInit                                                                  \
220
    (XSPAN_NS(XSpanInternalDummyArg)(XSPAN_NS(XSpanInternalDummyArg)::make()))
221
#endif
222
223
XSPAN_NAMESPACE_END
224
225
#ifndef XSPAN_DELETED_FUNCTION
226
#define XSPAN_DELETED_FUNCTION = delete
227
#endif
228
229
// function/method constraints
230
#define XSPAN_REQUIRES_CONVERTIBLE_ONE_DIRECTION(From, To, RType)                                  \
231
    typename std::enable_if<XSPAN_NS(XSpan_is_convertible) < From, To>::value, RType > ::type
232
#define XSPAN_REQUIRES_CONVERTIBLE_ANY_DIRECTION(A, B, RType)                                      \
233
    typename std::enable_if<XSPAN_NS(XSpan_is_convertible) < A, B>::value ||                       \
234
        XSPAN_NS(XSpan_is_convertible)<B, A>::value,                                               \
235
        RType > ::type
236
// note: these use "T" and "U"
237
#define XSPAN_REQUIRES_CONVERTIBLE_R(RType) XSPAN_REQUIRES_CONVERTIBLE_ONE_DIRECTION(U, T, RType)
238
#define XSPAN_REQUIRES_CONVERTIBLE_A                                                               \
239
    XSPAN_REQUIRES_CONVERTIBLE_R(XSPAN_NS(XSpanInternalDummyArg)) = XSpanInternalDummyArgInit
240
#define XSPAN_REQUIRES_CONVERTIBLE_T XSPAN_REQUIRES_CONVERTIBLE_R(XSPAN_NS(XSpanInternalDummyArg))
241
// note: these use "T" and "U"
242
#define XSPAN_REQUIRES_SIZE_1_R(RType)                                                             \
243
    typename std::enable_if<XSPAN_NS(XSpan_is_convertible) < U, T>::value &&XSPAN_NS(              \
244
        ValueForSizeOf)<T>::value == 1 &&                                                          \
245
        XSPAN_NS(ValueForSizeOf)<U>::value == 1,                                                   \
246
        RType > ::type
247
#define XSPAN_REQUIRES_SIZE_1_A                                                                    \
248
    XSPAN_REQUIRES_SIZE_1_R(XSPAN_NS(XSpanInternalDummyArg)) = XSpanInternalDummyArgInit
249
250
#include "xspan_impl_ptr_or_null.h"
251
#include "xspan_impl_ptr_or_span.h"
252
#include "xspan_impl_span.h"
253
#include "xspan_impl_ptr.h"
254
255
#undef XSPAN_REQUIRES_CONVERTIBLE_ONE_DIRECTION
256
#undef XSPAN_REQUIRES_CONVERTIBLE_ANY_DIRECTION
257
#undef XSPAN_REQUIRES_CONVERTIBLE_A
258
#undef XSPAN_REQUIRES_CONVERTIBLE_R
259
#undef XSPAN_REQUIRES_CONVERTIBLE_T
260
#undef XSPAN_REQUIRES_SIZE_1_A
261
#undef XSPAN_REQUIRES_SIZE_1_R
262
263
#endif // WITH_XSPAN
264
265
/* vim:set ts=4 sw=4 et: */