<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - No warning on truncation of integers when using make_unique/shared"
   href="https://bugs.llvm.org/show_bug.cgi?id=37552">37552</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>No warning on truncation of integers when using make_unique/shared
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>helge@penne.no
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following code fails to correctly produce a warning (with -Wall and
-Wextra) when the int is converted to uint8_t inside make_unique and the value
is modified from 0x100 to 0:

#include <cstdint>
#include <memory>

struct Foo {
    uint8_t m_v;
    Foo(uint8_t v) : m_v{v} {}
};

void f() {
    auto a = std::make_unique<Foo>(0x100); // No warning with any compiler
options
    auto b = std::unique_ptr<Foo>(new Foo(0x100)); // Warning with default
options
}

Same for make_shared and possibly also allocate_shared.  This is probably due
to warnings being disabled in the library.

Security critical code needs warnings on all integer conversions that can
result in truncation or altered values.  This bug means that the use of
make_unique/make_shared is unsafe, and should not be permitted at all in
security critical products that compile with clang.  That makes this a somewhat
critical bug.

Similar problems exist with the "emplace" family of functions, but I see those
as less critical (but I might be wrong).  Developers are probably more likely
to use the old functions than emplace to insert integers into collections,
while make_unique/shared is used quite frequently.

This problem illustrates the danger of disabling warnings in header libraries
that makes use of templates.  When the template "generates" code on behalf of
the programmer and warnings are off, then important warnings may fail to be
issued.  This is likely to get worse as the standard libraries get more
advanced over time.  The policy of disabling all warnings in libraries is
inherently dangerous and should ideally be reviewed...</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>