]> git.proxmox.com Git - mirror_qemu.git/commitdiff
libdecnumber: Fix decNumberSetBCD
authorTom Musta <tommusta@gmail.com>
Mon, 21 Apr 2014 20:54:55 +0000 (15:54 -0500)
committerAlexander Graf <agraf@suse.de>
Mon, 16 Jun 2014 11:24:29 +0000 (13:24 +0200)
Fix a simple bug in the decNumberSetBCD() function.  This function
encodes a decNumber with "n" BCD digits.  The original code erroneously
computed the number of declets from the dn argument, which is the output
decNumber value, and hence may contain garbage.  Instead, the input "n"
value is used.

Signed-off-by: Tom Musta <tommusta@gmail.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
libdecnumber/decNumber.c

index 6164a775092fde4ecabf66e3d3e50b2642063691..a30632f94ec213a9d72ee3ca62eb46677e41fc3e 100644 (file)
@@ -3541,7 +3541,7 @@ uByte * decNumberGetBCD(const decNumber *dn, uint8_t *bcd) {
 /* and bcd[0] zero.                                                  */
 /* ------------------------------------------------------------------ */
 decNumber * decNumberSetBCD(decNumber *dn, const uByte *bcd, uInt n) {
-  Unit *up=dn->lsu+D2U(dn->digits)-1;  /* -> msu [target pointer] */
+  Unit *up = dn->lsu + D2U(n) - 1;      /* -> msu [target pointer] */
   const uByte *ub=bcd;                 /* -> source msd */
 
   #if DECDPUN==1                       /* trivial simple copy */