Commit ab1b5847 authored by Michael Beck's avatar Michael Beck
Browse files

fixed broken get_tarval_sub_bits() implementation: now correctly clip number of bits

[r15417]
parent bddef28a
......@@ -1268,13 +1268,17 @@ unsigned char sc_sub_bits(const void *value, int len, unsigned byte_ofs) {
unsigned char res;
/* the current scheme uses one byte to store a nibble */
if (nibble_ofs >= len)
if (4 * nibble_ofs >= len)
return 0;
res = _val(val[nibble_ofs]);
if (len > nibble_ofs + 1)
if (len > 4 * (nibble_ofs + 1))
res |= _val(val[nibble_ofs + 1]) << 4;
/* kick bits outsize */
if (len < 8*byte_ofs) {
res &= 0xFF >> (8*byte_ofs - len);
}
return res;
}
......
......@@ -189,6 +189,14 @@ int sc_get_lowest_set_bit(const void *value);
int sc_is_zero(const void *value);
int sc_is_negative(const void *value);
int sc_had_carry(void);
/**
* Return the bits of a tarval at a given byte-offset.
*
* @param value the value
* @param len number of valid bits in the value
* @param byte_ofs the byte offset
*/
unsigned char sc_sub_bits(const void *value, int len, unsigned byte_ofs);
/**
......
......@@ -1479,7 +1479,7 @@ char *get_tarval_bitpattern(tarval *tv) {
unsigned char get_tarval_sub_bits(tarval *tv, unsigned byte_ofs) {
switch (get_mode_arithmetic(tv->mode)) {
case irma_twos_complement:
return sc_sub_bits(tv->value, tv->length, byte_ofs);
return sc_sub_bits(tv->value, get_mode_size_bits(tv->mode), byte_ofs);
case irma_ieee754:
return fc_sub_bits(tv->value, get_mode_size_bits(tv->mode), byte_ofs);
default:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment