commit cb60fba64e70a5ac479ba152073d7dc75b91d7fc
parent 3b9f04f6384e6372673bf857f05e502e8c01b6d0
Author: Christian Grothoff <christian@grothoff.org>
Date: Wed, 29 Jul 2026 13:06:36 +0200
ES_DNI: use the 7-digit multiplier for Y/Z-prefixed NIE numbers
Diffstat:
1 file changed, 7 insertions(+), 17 deletions(-)
diff --git a/src/reducer/validation_ES_DNI.c b/src/reducer/validation_ES_DNI.c
@@ -149,27 +149,17 @@ ES_DNI_check (const char *dni_number)
case 'Z':
/* NIE */
fact = dni_number[0] - 'X';
- /* 7 or 8 digits */
- if (2 == sscanf (&dni_number[1],
- "%8u%c%c",
+ /* NIE has exactly 7 digits after the X/Y/Z prefix. The prefix maps
+ X->0, Y->1, Z->2 and is prepended, i.e. it contributes fact * 10^7.
+ (A greedy "%8u" would still match the 7 digits and mis-scale by 10x,
+ breaking every Y- and Z-series NIE.) */
+ if (2 != sscanf (&dni_number[1],
+ "%7u%c%c",
&num,
&chksum,
&dummy))
- {
- num += fact * 100000000;
- }
- else if (2 == sscanf (&dni_number[1],
- "%7u%c%c",
- &num,
- &chksum,
- &dummy))
- {
- num += fact * 10000000;
- }
- else
- {
return false;
- }
+ num += fact * 10000000;
break;
default:
fact = 0;