Avoid potential buffer overrun in bd2str caused by signed char

Use uint8_t to avoid sign extension as char's may be signed.
As a further safeguard, use snprintf()

(cherry picked from commit f2fc54d237a24dc4db307cb56a513a8720809f95)

Change-Id: Iba6cc85ed19f0d9e981e52498817178e7ee7e341