Skip to content

More extensive use of std::ostringstream#3228

Merged
Lestropie merged 1 commit intodevfrom
more_ostringstream
Oct 29, 2025
Merged

More extensive use of std::ostringstream#3228
Lestropie merged 1 commit intodevfrom
more_ostringstream

Conversation

@Lestropie
Copy link
Member

Addresses a compilation issue that arose when attempting to compile a container for an external project using the ci-release-checks preset. Looks like a FP to me, but regardless, std::ostringstream is more suitable than MR::add_line() where all content for a single string is created sequentially.

25.46 FAILED: cpp/core/CMakeFiles/mrtrix-core.dir/dwi/gradient.cpp.o 
25.46 /usr/bin/c++ -DMRTRIX_BASE_VERSION=\"3.0.7\" -DMRTRIX_BUILD_TYPE=\"Release\" -DMRTRIX_HAVE_LGAMMA_R -DMRTRIX_PNG_SUPPORT -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -Dmrtrix_core_EXPORTS -I/src/mrtrix3/cpp/core -I/src/mrtrix3/build/_deps/eigen3-src -I/src/mrtrix3/build/_deps/json-src/include -I/src/mrtrix3/build/_deps/nifti1-src -I/src/mrtrix3/build/_deps/nifti2-src -I/src/mrtrix3/build/_deps/half-src/include -O3 -DNDEBUG -fPIC -Werror -std=gnu++17 -Winvalid-pch -include /src/mrtrix3/build/cpp/core/CMakeFiles/mrtrix-core.dir/cmake_pch.hxx -MD -MT cpp/core/CMakeFiles/mrtrix-core.dir/dwi/gradient.cpp.o -MF cpp/core/CMakeFiles/mrtrix-core.dir/dwi/gradient.cpp.o.d -o cpp/core/CMakeFiles/mrtrix-core.dir/dwi/gradient.cpp.o -c /src/mrtrix3/cpp/core/dwi/gradient.cpp
25.47 In file included from /usr/include/c++/12/ios:40,
25.47                  from /usr/include/c++/12/istream:38,
25.47                  from /usr/include/c++/12/sstream:38,
25.47                  from /usr/include/c++/12/complex:45,
25.47                  from /src/mrtrix3/cpp/core/types.h:20,
25.47                  from /src/mrtrix3/cpp/core/exception.h:19,
25.47                  from /src/mrtrix3/build/cpp/core/CMakeFiles/mrtrix-core.dir/cmake_pch.hxx:5,
25.47                  from <command-line>:
25.47 In static member function 'static std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)',
25.47     inlined from 'static void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' at /usr/include/c++/12/bits/basic_string.h:423:21,
25.47     inlined from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' at /usr/include/c++/12/bits/basic_string.tcc:532:22,
25.47     inlined from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' at /usr/include/c++/12/bits/basic_string.h:2171:19,
25.47     inlined from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::insert(size_type, const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' at /usr/include/c++/12/bits/basic_string.h:1928:22,
25.47     inlined from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]' at /usr/include/c++/12/bits/basic_string.h:3541:36,
25.47     inlined from 'std::string MR::DWI::{anonymous}::scheme2str(const MatrixType&) [with MatrixType = Eigen::Matrix<double, -1, -1>]' at /src/mrtrix3/cpp/core/dwi/gradient.h:116:12,
25.47     inlined from 'void MR::DWI::set_DW_scheme(MR::Header&, const MatrixType&) [with MatrixType = Eigen::Matrix<double, -1, -1>]' at /src/mrtrix3/cpp/core/dwi/gradient.h:136:34:
25.47 /usr/include/c++/12/bits/char_traits.h:431:56: error: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' specified bound between 9223372036854775810 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
25.47   431 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
25.47       |                                        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
25.47 cc1plus: all warnings being treated as errors

@Lestropie Lestropie self-assigned this Oct 28, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

<< frame.TD << "," << frame.sequence_type << "," << frame.echo_spacing << "," << frame.echo_train_len << ","
<< frame.read_dir[0] << "," << frame.read_dir[1] << "," << frame.read_dir[2] << "," << frame.pe_dir[0]
<< "," << frame.pe_dir[1] << "," << frame.pe_dir[2] << "," << frame.slice_dir[0] << ","
<< frame.slice_dir[1] << "," << frame.slice_dir[2] << "," << frame.label << "," << frame.name << ","

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

            << frame.slice_dir[1] << "," << frame.slice_dir[2] << "," << frame.label << "," << frame.name << ","
                                                                                               ^

@Lestropie Lestropie merged commit 7a566e1 into dev Oct 29, 2025
6 checks passed
@Lestropie Lestropie deleted the more_ostringstream branch October 29, 2025 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant