qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Should we check arguments for function `from_bcd` and `to_b


From: Su Hang
Subject: [Qemu-devel] Should we check arguments for function `from_bcd` and `to_bcd`?
Date: Thu, 22 Mar 2018 15:03:03 +0800 (GMT+08:00)

When I was reading 'qemu/hw/timer/m48t59.c'(Line:328) and run with
`make check-qtest-ppc`,
I found when write an invalid value 0xc to address 0x1FFF,
`from_bcd` return 12 instead of raising an exception(or error).

"""(qemu/hw/timer/m48t59.c)
    case 0x1FFF:
    case 0x07FF:
        /* year */
    tmp = from_bcd(val);
    if (tmp >= 0 && tmp <= 99) {
"""


"""(qemu/include/qemu/bcd.h)
/* Convert a byte between binary and BCD.  */
static inline uint8_t to_bcd(uint8_t val)
{
    return ((val / 10) << 4) | (val % 10);
}

static inline uint8_t from_bcd(uint8_t val)
{
    return ((val >> 4) * 10) + (val & 0x0f);
}
"""

Su Hang

reply via email to

[Prev in Thread] Current Thread [Next in Thread]