From 0737cffda23782d3b4776010a3202bd3c9a94cc7 Mon Sep 17 00:00:00 2001 From: Moritz Kroll Date: Mon, 2 Mar 2009 16:05:56 +0000 Subject: [PATCH] - Fixed masking of upper nibble of bitfield constants for tarval string output. - Report an error if reading a tarval string with unappropriate characters for the base indicated by the base prefix - Use "0x" prefix, when writing irms_int_number native (hex) values. [r25594] --- ir/tv/strcalc.c | 12 ++++++------ ir/tv/tv.c | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ir/tv/strcalc.c b/ir/tv/strcalc.c index 0ea940a6b..804a071c4 100644 --- a/ir/tv/strcalc.c +++ b/ir/tv/strcalc.c @@ -1019,7 +1019,7 @@ void sc_val_from_str(const char *str, unsigned int len, void *buffer, ir_mode *m case 'c': case 'b': case 'a': - if (base[0] > SC_9 || base[1] > SC_0) { /* (base > 10) */ + if (base[0] > SC_A || base[1] > SC_0) { /* (base > 10) */ val[0] = _digit((*str)-'a'+10); } else @@ -1032,7 +1032,7 @@ void sc_val_from_str(const char *str, unsigned int len, void *buffer, ir_mode *m case 'C': case 'B': case 'A': - if (base[0] > SC_9 || base[1] > SC_0) { /* (base > 10) */ + if (base[0] > SC_A || base[1] > SC_0) { /* (base > 10) */ val[0] = _digit((*str)-'A'+10); } else @@ -1041,7 +1041,7 @@ void sc_val_from_str(const char *str, unsigned int len, void *buffer, ir_mode *m case '9': case '8': - if (base[0] > SC_7 || base[1] > SC_0) { /* (base > 8) */ + if (base[0] > SC_8 || base[1] > SC_0) { /* (base > 8) */ val[0] = _digit((*str)-'0'); } else @@ -1372,7 +1372,7 @@ const char *sc_print(const void *value, unsigned bits, enum base_t base, int sig /* last nibble must be masked */ if (bits & 3) { - mask = zex_digit[bits & 3]; + mask = zex_digit[(bits & 3) - 1]; x = and_table[_val(val[counter++])][mask]; *(--pos) = digits[_val(x)]; } @@ -1399,7 +1399,7 @@ const char *sc_print(const void *value, unsigned bits, enum base_t base, int sig /* last nibble must be masked */ if (bits & 3) { - mask = zex_digit[bits & 3]; + mask = zex_digit[(bits & 3) - 1]; x = and_table[_val(val[counter++])][mask]; pos -= 4; @@ -1439,7 +1439,7 @@ const char *sc_print(const void *value, unsigned bits, enum base_t base, int sig /* last nibble must be masked */ if (bits & 3) { - mask = zex_digit[bits & 3]; + mask = zex_digit[(bits & 3) - 1]; div1_res[counter] = and_table[_val(p[counter])][mask]; ++counter; } diff --git a/ir/tv/tv.c b/ir/tv/tv.c index 41442e66b..49ec584d8 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -1451,8 +1451,9 @@ int tarval_snprintf(char *buf, size_t len, tarval *tv) { str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT, 0); break; - case TVO_HEX: case TVO_NATIVE: + prefix = "0x"; + case TVO_HEX: default: str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX, 0); break; -- 2.20.1