https://bugs.kde.org/show_bug.cgi?id=433857

            Bug ID: 433857
           Summary: Add validation to C++17 aligned new/delete alignment
                    size
           Product: valgrind
           Version: unspecified
          Platform: Other
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: memcheck
          Assignee: jsew...@acm.org
          Reporter: pjfl...@wanadoo.fr
  Target Milestone: ---

According to

https://en.cppreference.com/w/cpp/memory/new/operator_new

a) these operators should only be called when the alignment is greater than
__STDCPP_DEFAULT_NEW_ALIGNMENT__ (the contrary would either mean a compiler bug
or an explicit call to the operator with an alignment that it too small)

b) "The behavior is undefined if this is not a valid alignment value "

c) I suppose that the alignment size passed to new should match that passed to
delete.

For point b) the wording of the C++ 17 standard is

"6.6.5 Alignment

4 Alignments are represented as values of the type std::size_t. Valid
alignments include only those values
returned by an alignof expression for the fundamental types plus an additional
implementation-defined set
of values, which may be empty. Every alignment value shall be a non-negative
integral power of two."

For point b) I suggest just checking that the alignment is a power of 2.

Point c) looks more complicated, and I'll look at that another time.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to