[PATCH] D48251: Assert on implicit truncation in llvm::endian::Writer

Jordan Rose via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 15 18:00:59 PDT 2018


jordan_rose created this revision.
jordan_rose added a reviewer: pcc.

llvm::endian::Writer is often used to serialize for binary formats, which makes it attractive to explicitly provide template arguments for the type being written. However, this can also lead to accidental truncation of data, which can lead to corruption of the serialized archive. (Real-world example: https://github.com/apple/swift/pull/17265.) Add assertions for this sort of accidental truncation with integer types, and for overflow errors with floating-point types, while preserving the existing behavior when the template argument is //not// provided explicitly.


Repository:
  rL LLVM

https://reviews.llvm.org/D48251

Files:
  include/llvm/Support/EndianStream.h
  unittests/Support/EndianStreamTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48251.151595.patch
Type: text/x-patch
Size: 5687 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180616/e8a3dd7c/attachment.bin>


More information about the llvm-commits mailing list