Subject: [Boost-bugs] [Boost C++ Libraries] #13223: Undefined behavior inside assign_bits while importing data to cpp_int
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-09-21 12:40:13
#13223: Undefined behavior inside assign_bits while importing data to cpp_int
--------------------------------+----------------------------
Reporter: Dennis <yowidin@â¦> | Owner: John Maddock
Type: Bugs | Status: new
Milestone: To Be Determined | Component: multiprecision
Version: Boost 1.64.0 | Severity: Problem
Keywords: |
--------------------------------+----------------------------
Trying to import bits from unsigned char array results in undefined
behavior as reported by Clang.
Minimal example:
{{{#!cpp
#include <iostream>
#include <cstdint>
#include <boost/multiprecision/cpp_int.hpp>
using mp_int_t = boost::multiprecision::int128_t;
using source_t = std::vector<std::uint8_t>;
int main() {
source_t src(16, 0);
mp_int_t result;
import_bits(result, src.begin(), src.end(), 0, false);
return 0;
}
}}}
Compile command:
{{{#!bash
clang++ main.cpp \
-g -O1 -fsanitize=undefined -fno-omit-frame-pointer \
-fno-optimize-sibling-calls -std=c++11 -o main
}}}
Runtime output:
{{{
boost/multiprecision/cpp_int/import_export.hpp:64:21: runtime error: shift
exponent 128 is too large for 8-bit type 'unsigned char'
}}}
Environment information:
- Ubuntu 16.04 LTS 64bit
- Tested with Clang 3.8.0 and Clang 5.0.0
-- Ticket URL: <https://svn.boost.org/trac10/boost/ticket/13223> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-09-21 12:45:53 UTC