lib: abtol: Fix number digits in hex number conversion.

After a letter based digit, number based digits are off.

* lib/mes/abtol.c (abtol): Reset "m" for number based digit.
* lib/tests/stdlib/70-strtoull.c (main): Test it.
* lib/tests/stdlib/90-strtol.c (main): Likewise.
This commit is contained in:
Rick Masters 2022-10-07 11:59:57 +02:00 committed by Jan (janneke) Nieuwenhuizen
parent 31e5f2e476
commit 9b1f71a372
3 changed files with 24 additions and 7 deletions

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2022 Rick Masters <grick23@gmail.com>
*
* This file is part of GNU Mes.
*
@ -44,6 +45,8 @@ abtol (char const **p, int base)
i = i * base;
if (s[0] > '9')
m = 'a' - 10;
else
m = '0';
i = i + s[0] - m;
s = s + 1;
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2022 Rick Masters <grick23@gmail.com>
*
* This file is part of GNU Mes.
*
@ -43,5 +44,13 @@ main ()
if (strcmp (p, "zar\n"))
return 4;
p = "a2zar\n";
n = strtoull (p, (char **) &p, 16);
if (n != 162)
return 5;
eputs (p);
if (strcmp (p, "zar\n"))
return 6;
return 0;
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2022 Rick Masters <grick23@gmail.com>
*
* This file is part of GNU Mes.
*
@ -28,25 +29,29 @@ main ()
if (strtol ("0x12", 0, 0) != 18)
1;
eputs ("012\n");
if (strtol ("012", 0, 0) != 10)
eputs ("0xa2\n");
if (strtol ("0xa2", 0, 0) != 162)
2;
eputs ("-1\n");
if (strtol ("-1", 0, 0) != -1)
eputs ("012\n");
if (strtol ("012", 0, 0) != 10)
3;
eputs ("-1\n");
if (strtoul ("-1", 0, 0) != -1)
if (strtol ("-1", 0, 0) != -1)
4;
eputs ("-1\n");
if (strtoul ("-1", 0, 0) != -1)
5;
char *p = "16";
int n = strtol (p, (char **) &p, 0);
eputs ("p=");
eputs (p);
eputs ("\n");
if (*p != 0)
return 5;
return 6;
p = "0x12";
n = strtol (p, (char **) &p, 0);
@ -54,7 +59,7 @@ main ()
eputs (p);
eputs ("\n");
if (*p != 0)
return 5;
return 7;
return 0;