Fix a problem with CIF checksum due to using char instead of int
This commit is contained in:
parent
c229754d6a
commit
9635b2f3a3
|
@ -1,3 +1,9 @@
|
|||
vat (0.0-2) bookworm; urgency=medium
|
||||
|
||||
* Fix CIF computation.
|
||||
|
||||
-- jordi fita mas <jordi@tandem.blog> Sat, 21 Jan 2023 19:41:05 +0002
|
||||
|
||||
vat (0.0-1) bullseye; urgency=medium
|
||||
|
||||
* Initial release.
|
||||
|
|
2
es.c
2
es.c
|
@ -50,7 +50,7 @@ valid_cif(const char *cif) {
|
|||
if (n % 2 == 0) {
|
||||
evens += cif[n] - 48;
|
||||
} else {
|
||||
int d = cif[n] * 2;
|
||||
int d = (cif[n] - 48) * 2;
|
||||
int a = d / 10;
|
||||
int b = d % 10;
|
||||
odds += a + b;
|
||||
|
|
|
@ -7,11 +7,12 @@ SELECT 'ES40404040D'::VATIN,
|
|||
'ES40404040-D'::VATIN,
|
||||
' esx0523821l '::VATIN,
|
||||
'ESM0243487d'::VATIN,
|
||||
' ESb17616756 '::VATIN
|
||||
' ESb17616756 '::VATIN,
|
||||
'ESb17385717'::VATIN
|
||||
;
|
||||
vatin | vatin | vatin | vatin | vatin
|
||||
-------------+-------------+-------------+-------------+-------------
|
||||
ES40404040D | ES40404040D | ESX0523821L | ESM0243487D | ESB17616756
|
||||
vatin | vatin | vatin | vatin | vatin | vatin
|
||||
-------------+-------------+-------------+-------------+-------------+-------------
|
||||
ES40404040D | ES40404040D | ESX0523821L | ESM0243487D | ESB17616756 | ESB17385717
|
||||
(1 row)
|
||||
|
||||
-- Test invalid checksums
|
||||
|
|
|
@ -9,7 +9,8 @@ SELECT 'ES40404040D'::VATIN,
|
|||
'ES40404040-D'::VATIN,
|
||||
' esx0523821l '::VATIN,
|
||||
'ESM0243487d'::VATIN,
|
||||
' ESb17616756 '::VATIN
|
||||
' ESb17616756 '::VATIN,
|
||||
'ESb17385717'::VATIN
|
||||
;
|
||||
|
||||
-- Test invalid checksums
|
||||
|
|
Loading…
Reference in New Issue