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:
parent
2cfce3186b
commit
fdac9fd3f2
|
@ -1,6 +1,7 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* 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.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -44,6 +45,8 @@ abtol (char const **p, int base)
|
||||||
i = i * base;
|
i = i * base;
|
||||||
if (s[0] > '9')
|
if (s[0] > '9')
|
||||||
m = 'a' - 10;
|
m = 'a' - 10;
|
||||||
|
else
|
||||||
|
m = '0';
|
||||||
i = i + s[0] - m;
|
i = i + s[0] - m;
|
||||||
s = s + 1;
|
s = s + 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
* Copyright © 2022 Rick Masters <grick23@gmail.com>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -43,5 +44,13 @@ main ()
|
||||||
if (strcmp (p, "zar\n"))
|
if (strcmp (p, "zar\n"))
|
||||||
return 4;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
* Copyright © 2022 Rick Masters <grick23@gmail.com>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -28,25 +29,29 @@ main ()
|
||||||
if (strtol ("0x12", 0, 0) != 18)
|
if (strtol ("0x12", 0, 0) != 18)
|
||||||
1;
|
1;
|
||||||
|
|
||||||
eputs ("012\n");
|
eputs ("0xa2\n");
|
||||||
if (strtol ("012", 0, 0) != 10)
|
if (strtol ("0xa2", 0, 0) != 162)
|
||||||
2;
|
2;
|
||||||
|
|
||||||
eputs ("-1\n");
|
eputs ("012\n");
|
||||||
if (strtol ("-1", 0, 0) != -1)
|
if (strtol ("012", 0, 0) != 10)
|
||||||
3;
|
3;
|
||||||
|
|
||||||
eputs ("-1\n");
|
eputs ("-1\n");
|
||||||
if (strtoul ("-1", 0, 0) != -1)
|
if (strtol ("-1", 0, 0) != -1)
|
||||||
4;
|
4;
|
||||||
|
|
||||||
|
eputs ("-1\n");
|
||||||
|
if (strtoul ("-1", 0, 0) != -1)
|
||||||
|
5;
|
||||||
|
|
||||||
char *p = "16";
|
char *p = "16";
|
||||||
int n = strtol (p, (char **) &p, 0);
|
int n = strtol (p, (char **) &p, 0);
|
||||||
eputs ("p=");
|
eputs ("p=");
|
||||||
eputs (p);
|
eputs (p);
|
||||||
eputs ("\n");
|
eputs ("\n");
|
||||||
if (*p != 0)
|
if (*p != 0)
|
||||||
return 5;
|
return 6;
|
||||||
|
|
||||||
p = "0x12";
|
p = "0x12";
|
||||||
n = strtol (p, (char **) &p, 0);
|
n = strtol (p, (char **) &p, 0);
|
||||||
|
@ -54,7 +59,7 @@ main ()
|
||||||
eputs (p);
|
eputs (p);
|
||||||
eputs ("\n");
|
eputs ("\n");
|
||||||
if (*p != 0)
|
if (*p != 0)
|
||||||
return 5;
|
return 7;
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue