Skip to contentSkip to conversation

bcd: limit bin2bcd input value to lie between 0-99

PATCH New [email protected] 1 participant 1 message Nov 15, 2011 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcd: limit bin2bcd input value to lie between 0-99

From: venu byravarasu <[email protected]>

If bin2bcd gets a value which is more than 100, there are chances that it may store non decimal value in the most significant nibble.

e.g. say val passed to bin2bcd is 112.
In that case the expected value to be returned by this function is 12.
However, without the fix being added it would be 112.

---
 lib/bcd.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
lib/bcd.c +1 -0
index d74257f..d715474 100644
@@ -9,6 +9,7 @@ EXPORT_SYMBOL(bcd2bin);
 
 unsigned char bin2bcd(unsigned val)
 {
+	val %= 100;
 	return ((val / 10) << 4) + val % 10;
 }
 EXPORT_SYMBOL(bin2bcd);
Signature · 1 line
1.7.1.1