@@ -106,7 +106,7 @@ inline string<Capacity>::string(const char (&other)[N]) noexcept
106
106
template <uint64_t Capacity>
107
107
// NOLINTNEXTLINE(hicpp-named-parameter, readability-named-parameter) justification in header
108
108
inline string<Capacity>::string(TruncateToCapacity_t, const char * const other) noexcept
109
- : string(TruncateToCapacity, other, [&other]() -> uint64_t {
109
+ : string(TruncateToCapacity, other, [&other]() noexcept -> uint64_t {
110
110
return (other != nullptr ) ? strnlen (other, Capacity) : 0U ;
111
111
}())
112
112
{
@@ -123,13 +123,13 @@ inline string<Capacity>::string(TruncateToCapacity_t, const char* const other, c
123
123
}
124
124
else if (Capacity < count)
125
125
{
126
- // AXIVION DISABLE STYLE AutosarC++19_03-A16.0.1: conditional compilation is required for setting gcc diagnostics, since
126
+ // AXIVION DISABLE STYLE AutosarC++19_03-A16.0.1, AutosarC++19_03-A16.7.1 : conditional compilation is required for setting gcc diagnostics, since
127
127
// gcc 8 incorrectly warns here about out of bounds array access
128
128
#if (defined(__GNUC__) && (__GNUC__ == 8)) && (__GNUC_MINOR__ >= 3)
129
129
#pragma GCC diagnostic push
130
130
#pragma GCC diagnostic ignored "-Warray-bounds"
131
131
#endif
132
- std::memcpy (&( m_rawstring[ 0 ]) , other, Capacity);
132
+ std::memcpy (m_rawstring, other, Capacity);
133
133
#if (defined(__GNUC__) && (__GNUC__ == 8)) && (__GNUC_MINOR__ >= 3)
134
134
#pragma GCC diagnostic pop
135
135
#endif
@@ -142,7 +142,7 @@ inline string<Capacity>::string(TruncateToCapacity_t, const char* const other, c
142
142
}
143
143
else
144
144
{
145
- std::memcpy (&( m_rawstring[ 0 ]) , other, count);
145
+ std::memcpy (m_rawstring, other, count);
146
146
m_rawstring[count] = ' \0 ' ;
147
147
m_rawstringSize = count;
148
148
}
@@ -162,9 +162,9 @@ inline string<Capacity>& string<Capacity>::operator=(const char (&rhs)[N]) noexc
162
162
return *this ;
163
163
}
164
164
165
- std::memcpy (&( m_rawstring[ 0 ]) , rhs, N);
165
+ std::memcpy (m_rawstring, rhs, N);
166
166
167
- m_rawstringSize = std::min (Capacity, static_cast <uint64_t >(strnlen (rhs, N)));
167
+ m_rawstringSize = std::min (Capacity, static_cast <uint64_t >(strnlen (& rhs[ 0 ] , N)));
168
168
m_rawstring[m_rawstringSize] = ' \0 ' ;
169
169
170
170
if (rhs[m_rawstringSize] != ' \0 ' )
@@ -209,7 +209,7 @@ inline bool string<Capacity>::unsafe_assign(const char* const str) noexcept
209
209
<< Capacity << " ) of the fixed string." ;
210
210
return false ;
211
211
}
212
- std::memcpy (&( m_rawstring[ 0 ]) , str, strSize);
212
+ std::memcpy (m_rawstring, str, strSize);
213
213
m_rawstring[strSize] = ' \0 ' ;
214
214
m_rawstringSize = strSize;
215
215
return true ;
@@ -219,23 +219,24 @@ template <uint64_t Capacity>
219
219
template <typename T>
220
220
inline IsStringOrCharArray<T, int64_t > string<Capacity>::compare(const T& other) const noexcept
221
221
{
222
- uint64_t otherSize{internal::GetSize<T>::call (other)};
223
- auto result = memcmp (c_str (), internal::GetData<T>::call (other), std::min (m_rawstringSize, otherSize));
222
+ const uint64_t otherSize{internal::GetSize<T>::call (other)};
223
+ const auto result = memcmp (c_str (), internal::GetData<T>::call (other), std::min (m_rawstringSize, otherSize));
224
224
if (result == 0 )
225
225
{
226
226
if (m_rawstringSize < otherSize)
227
227
{
228
228
return -1 ;
229
229
}
230
- return ((m_rawstringSize > otherSize) ? 1 : 0 );
230
+ const int64_t isLargerThanOther{(m_rawstringSize > otherSize) ? 1L : 0L };
231
+ return isLargerThanOther;
231
232
}
232
233
return result;
233
234
}
234
235
235
236
template <uint64_t Capacity>
236
237
inline int64_t string<Capacity>::compare(char other) const noexcept
237
238
{
238
- auto result = memcmp (c_str (), &other, 1U );
239
+ const auto result = memcmp (c_str (), &other, 1U );
239
240
if (result == 0 )
240
241
{
241
242
if (empty ())
@@ -250,7 +251,7 @@ inline int64_t string<Capacity>::compare(char other) const noexcept
250
251
template <uint64_t Capacity>
251
252
inline const char * string<Capacity>::c_str() const noexcept
252
253
{
253
- return & m_rawstring[ 0 ] ;
254
+ return m_rawstring;
254
255
}
255
256
256
257
template <uint64_t Capacity>
@@ -284,8 +285,8 @@ inline string<Capacity>& string<Capacity>::copy(const string<N>& rhs) noexcept
284
285
{
285
286
static_assert (N <= Capacity,
286
287
" Assignment failed. The capacity of the given fixed string is larger than the capacity of this." );
287
- uint64_t strSize{rhs.size ()};
288
- std::memcpy (&( m_rawstring[ 0 ]) , rhs.c_str (), strSize);
288
+ const uint64_t strSize{rhs.size ()};
289
+ std::memcpy (m_rawstring, rhs.c_str (), strSize);
289
290
m_rawstring[strSize] = ' \0 ' ;
290
291
m_rawstringSize = strSize;
291
292
return *this ;
@@ -298,7 +299,7 @@ inline string<Capacity>& string<Capacity>::move(string<N>&& rhs) noexcept
298
299
static_assert (N <= Capacity,
299
300
" Assignment failed. The capacity of the given fixed string is larger than the capacity of this." );
300
301
const uint64_t strSize{rhs.size ()};
301
- std::memcpy (&( m_rawstring[ 0 ]) , rhs.c_str (), strSize);
302
+ std::memcpy (m_rawstring, rhs.c_str (), strSize);
302
303
m_rawstring[strSize] = ' \0 ' ;
303
304
m_rawstringSize = strSize;
304
305
rhs.clear ();
@@ -341,8 +342,8 @@ concatenate(const T1& str1, const T2& str2) noexcept
341
342
uint64_t size2{internal::GetSize<T2>::call (str2)};
342
343
using NewStringType = string<internal::SumCapa<T1, T2>::value>;
343
344
NewStringType newString;
344
- std::memcpy (&( newString.m_rawstring [ 0 ]) , internal::GetData<T1>::call (str1), size1);
345
- std::memcpy (&( newString.m_rawstring [0 ]) + size1, internal::GetData<T2>::call (str2), size2);
345
+ std::memcpy (newString.m_rawstring , internal::GetData<T1>::call (str1), size1);
346
+ std::memcpy (&newString.m_rawstring [size1] , internal::GetData<T2>::call (str2), size2);
346
347
newString.m_rawstring [size1 + size2] = ' \0 ' ;
347
348
newString.m_rawstringSize = size1 + size2;
348
349
@@ -369,9 +370,9 @@ template <uint64_t Capacity>
369
370
template <typename T>
370
371
inline IsStringOrCharArrayOrChar<T, bool > string<Capacity>::unsafe_append(const T& str) noexcept
371
372
{
372
- uint64_t tSize{internal::GetSize<T>::call (str)};
373
- const char * tData{internal::GetData<T>::call (str)};
374
- uint64_t clampedTSize{std::min (Capacity - m_rawstringSize, tSize)};
373
+ const uint64_t tSize{internal::GetSize<T>::call (str)};
374
+ const char * const tData{internal::GetData<T>::call (str)};
375
+ const uint64_t clampedTSize{std::min (Capacity - m_rawstringSize, tSize)};
375
376
376
377
if (tSize > clampedTSize)
377
378
{
@@ -392,14 +393,14 @@ template <typename T>
392
393
inline IsStringOrCharArrayOrChar<T, string<Capacity>&> string<Capacity>::append(TruncateToCapacity_t,
393
394
const T& str) noexcept
394
395
{
395
- uint64_t tSize{internal::GetSize<T>::call (str)};
396
- const char * tData{internal::GetData<T>::call (str)};
397
- uint64_t clampedTSize{std::min (Capacity - m_rawstringSize, tSize)};
396
+ const uint64_t tSize{internal::GetSize<T>::call (str)};
397
+ const char * const tData{internal::GetData<T>::call (str)};
398
+ uint64_t const clampedTSize{std::min (Capacity - m_rawstringSize, tSize)};
398
399
399
400
std::memcpy (&(m_rawstring[m_rawstringSize]), tData, clampedTSize);
400
401
if (tSize > clampedTSize)
401
402
{
402
- IOX_LOG (WARN) << " The last " << (tSize - Capacity) + m_rawstringSize << " characters of " << tData
403
+ IOX_LOG (WARN) << " The last " << (tSize - clampedTSize) << " characters of " << tData
403
404
<< " are truncated, because the length is larger than the capacity." ;
404
405
}
405
406
@@ -430,6 +431,7 @@ template <typename T>
430
431
inline IsCxxStringOrCharArray<T, bool >
431
432
string<Capacity>::insert(const uint64_t pos, const T& str, const uint64_t count) noexcept
432
433
{
434
+ // AXIVION Next Construct AutosarC++19_03-M0.1.2, AutosarC++19_03-M0.1.9, FaultDetection-DeadBranches : False positive! Branching depends on input parameter
433
435
if (count > internal::GetSize<T>::call (str))
434
436
{
435
437
return false ;
@@ -441,6 +443,7 @@ string<Capacity>::insert(const uint64_t pos, const T& str, const uint64_t count)
441
443
return false ;
442
444
}
443
445
446
+ // AXIVION Next Construct AutosarC++19_03-M0.1.2, AutosarC++19_03-M0.1.9, FaultDetection-DeadBranches : False positive! Branching depends on input parameter
444
447
if (pos > m_rawstringSize)
445
448
{
446
449
return false ;
@@ -462,9 +465,9 @@ inline optional<string<Capacity>> string<Capacity>::substr(const uint64_t pos, c
462
465
return nullopt;
463
466
}
464
467
465
- uint64_t length{std::min (count, m_rawstringSize - pos)};
468
+ const uint64_t length{std::min (count, m_rawstringSize - pos)};
466
469
string subString;
467
- std::memcpy (&( subString.m_rawstring [ 0 ]) , &m_rawstring[pos], length);
470
+ std::memcpy (subString.m_rawstring , &m_rawstring[pos], length);
468
471
subString.m_rawstring [length] = ' \0 ' ;
469
472
subString.m_rawstringSize = length;
470
473
return subString;
@@ -498,15 +501,16 @@ template <typename T>
498
501
inline IsStringOrCharArray<T, optional<uint64_t >> string<Capacity>::find_first_of(const T& str,
499
502
const uint64_t pos) const noexcept
500
503
{
504
+ // AXIVION Next Construct AutosarC++19_03-M0.1.2, AutosarC++19_03-M0.1.9, FaultDetection-DeadBranches : False positive! Branching depends on input parameter
501
505
if (pos > m_rawstringSize)
502
506
{
503
507
return nullopt;
504
508
}
505
- const char * found{ nullptr };
506
- const char * data {internal::GetData <T>::call (str)};
509
+ const char * const data{internal::GetData<T>:: call (str) };
510
+ const uint64_t dataSize {internal::GetSize <T>::call (str)};
507
511
for (auto p = pos; p < m_rawstringSize; ++p)
508
512
{
509
- found = std::strchr (data, m_rawstring[p]) ;
513
+ const void * const found{ memchr (data, m_rawstring[p], dataSize)} ;
510
514
if (found != nullptr )
511
515
{
512
516
return p;
@@ -530,17 +534,17 @@ inline IsStringOrCharArray<T, optional<uint64_t>> string<Capacity>::find_last_of
530
534
{
531
535
p = m_rawstringSize - 1U ;
532
536
}
533
- const char * found{ nullptr };
534
- const char * data {internal::GetData <T>::call (str)};
537
+ const char * const data{internal::GetData<T>:: call (str) };
538
+ const uint64_t dataSize {internal::GetSize <T>::call (str)};
535
539
for (; p > 0U ; --p)
536
540
{
537
- found = std::strchr (data, m_rawstring[p]) ;
541
+ const void * const found{ memchr (data, m_rawstring[p], dataSize)} ;
538
542
if (found != nullptr )
539
543
{
540
544
return p;
541
545
}
542
546
}
543
- found = std::strchr (data, m_rawstring[p]) ;
547
+ const void * const found{ memchr (data, m_rawstring[p], dataSize)} ;
544
548
if (found != nullptr )
545
549
{
546
550
return 0U ;
@@ -614,12 +618,14 @@ inline IsStdStringOrCharArrayOrChar<T, bool> operator>=(const T& lhs, const stri
614
618
return (rhs.compare (lhs) <= 0 );
615
619
}
616
620
621
+ // AXIVION Next Construct AutosarC++19_03-A13.5.4 : Code reuse is established by a helper function
617
622
template <typename T, uint64_t Capacity>
618
623
inline IsStringOrCharArrayOrChar<T, bool > operator ==(const string<Capacity>& lhs, const T& rhs) noexcept
619
624
{
620
625
return (lhs.compare (rhs) == 0 );
621
626
}
622
627
628
+ // AXIVION Next Construct AutosarC++19_03-A13.5.4 : Code reuse is established by a helper function
623
629
template <typename T, uint64_t Capacity>
624
630
inline IsStringOrCharArrayOrChar<T, bool > operator !=(const string<Capacity>& lhs, const T& rhs) noexcept
625
631
{
0 commit comments