Closed alejandro-colomar closed 3 months ago
@lamby
I was wondering... maybe I could write a library, libgetnum
, and add these functions there. That way, all those code bases in Debian that have the problem we found in gettime()
could be fixed easily by just calling getnum()
internally as I did here.
I also fixed so many other hidden bugs in this PR, that other projects could benefit from such a library.
@lamby
I've written a library with functions similar to these. If you're interested in packaging it for debian, let me know.
https://www.alejandro-colomar.es/src/alx/alx/liba2i.git/
alx@debian:~/tmp$ cat a.c
#include <a2i/a2i.h>
#include <a2i/str2i.h>
#include <err.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
int n;
if (a2i(int, &n, "42", NULL, 0, INT_MIN, INT_MAX) == -1) // similar to getnum()
err(EXIT_FAILURE, "a2i");
if (str2i(int, &n, "42") == -1) // similar to getn()
err(EXIT_FAILURE, "str2i");
printf("%d\n", n);
}
alx@debian:~/tmp$ cc -Wall -Wextra -Werror a.c $(pkgconf --cflags --libs liba2i)
alx@debian:~/tmp$ ./a.out
42
Let's start versioning these drafts.
v2 changes:
$ git range-diff gh/getuh..gh/atoi getuh..atoi
1: 9311208b = 1: 04c81059 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE
2: d419caf3 = 2: 27f28d7e lib/idmapping.c: get_map_ranges(): Rename local variable
3: fd1fc690 = 3: 7ed33c08 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls
4: f1c4d21f = 4: e82da50a lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
5: 06a1849a = 5: c23bd1c8 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
6: eb0baa23 = 6: 03d28aed lib/idmapping.c: get_map_ranges(): Remove dead code
7: cb69444d = 7: 48b3c9f7 lib/idmapping.c: get_map_ranges(): Simplify iterator variables
8: 4452c8d6 < -: -------- lib/idmapping.c: get_map_ranges(): Merge two input checks into a simpler one
9: 8919c4af = 8: beed7506 lib/idmapping.c: get_map_ranges(): Don't exit() from a library function
10: d5dd21e5 = 9: 34d65f3f lib/atoi/: Use libbsd's strto[iu](3bsd) when available
11: d505ecce = 10: 6c445f3a src/usermod.c: Rename identifiers ralated to [ug]id's
12: 5aada098 = 11: 159c25b6 src/usermod.c: Use id_t for parsing uid_t and gid_t
v2b changes:
$ git range-diff gh/getuh..gh/atoi getuh..atoi
1: 04c81059 = 1: 8bd63aa0 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE
2: 27f28d7e = 2: 66cf192f lib/idmapping.c: get_map_ranges(): Rename local variable
3: 7ed33c08 = 3: 2aff852c lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls
4: e82da50a = 4: a6696361 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
5: c23bd1c8 = 5: ec510642 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
6: 03d28aed = 6: bd600824 lib/idmapping.c: get_map_ranges(): Remove dead code
7: 48b3c9f7 = 7: 43e76ef0 lib/idmapping.c: get_map_ranges(): Simplify iterator variables
8: beed7506 = 8: c77169ad lib/idmapping.c: get_map_ranges(): Don't exit() from a library function
9: 34d65f3f = 9: 1770e532 lib/atoi/: Use libbsd's strto[iu](3bsd) when available
10: 6c445f3a = 10: 76dfdcea src/usermod.c: Rename identifiers ralated to [ug]id's
11: 159c25b6 = 11: 77dd2ebe src/usermod.c: Use id_t for parsing uid_t and gid_t
v2c changes:
$ git range-diff gh/getuh..gh/atoi getuh..atoi
1: 8bd63aa0 = 1: 866893d1 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE
2: 66cf192f = 2: 56d03242 lib/idmapping.c: get_map_ranges(): Rename local variable
3: 2aff852c = 3: 27db98a7 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls
4: a6696361 = 4: 2ede136b lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
5: ec510642 = 5: 70bc48dd lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
6: bd600824 = 6: 996d8aee lib/idmapping.c: get_map_ranges(): Remove dead code
7: 43e76ef0 = 7: dadba1db lib/idmapping.c: get_map_ranges(): Simplify iterator variables
8: c77169ad = 8: 4fa2c8a8 lib/idmapping.c: get_map_ranges(): Don't exit() from a library function
9: 1770e532 = 9: d0442533 lib/atoi/: Use libbsd's strto[iu](3bsd) when available
10: 76dfdcea = 10: ad6baf56 src/usermod.c: Rename identifiers ralated to [ug]id's
11: 77dd2ebe = 11: 0744efa9 src/usermod.c: Use id_t for parsing uid_t and gid_t
v2d changes:
$ git range-diff gh/getuh..gh/atoi getuh..atoi
1: 866893d1 = 1: 4b5bb91e lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE
2: 56d03242 = 2: 49ca8717 lib/idmapping.c: get_map_ranges(): Rename local variable
3: 27db98a7 = 3: 4ed4741e lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls
4: 2ede136b = 4: 150bfe11 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
5: 70bc48dd = 5: 749b80a1 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
6: 996d8aee = 6: 834934f6 lib/idmapping.c: get_map_ranges(): Remove dead code
7: dadba1db = 7: d5a72520 lib/idmapping.c: get_map_ranges(): Simplify iterator variables
8: 4fa2c8a8 = 8: edb0e3e1 lib/idmapping.c: get_map_ranges(): Don't exit() from a library function
9: d0442533 = 9: a6f7c040 lib/atoi/: Use libbsd's strto[iu](3bsd) when available
10: ad6baf56 = 10: 158aa953 src/usermod.c: Rename identifiers ralated to [ug]id's
11: 0744efa9 = 11: 1392e7f3 src/usermod.c: Use id_t for parsing uid_t and gid_t
v2e changes:
$ git range-diff gh/getuh..gh/atoi getuh..atoi
1: 4b5bb91e = 1: caaa1ba1 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE
2: 49ca8717 = 2: a8d319da lib/idmapping.c: get_map_ranges(): Rename local variable
3: 4ed4741e = 3: 8f69c62e lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls
4: 150bfe11 = 4: f50f2349 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
5: 749b80a1 = 5: 647c70d7 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
6: 834934f6 = 6: 0b28e062 lib/idmapping.c: get_map_ranges(): Remove dead code
7: d5a72520 = 7: 8bc60a8a lib/idmapping.c: get_map_ranges(): Simplify iterator variables
8: edb0e3e1 = 8: 439d8209 lib/idmapping.c: get_map_ranges(): Don't exit() from a library function
9: a6f7c040 ! 9: d709db6e lib/atoi/: Use libbsd's strto[iu](3bsd) when available
@@ lib/atoi/a2i.h
#include "atoi/strtoi.h"
#include "atoi/strtou_noneg.h"
-@@ lib/atoi/a2i.h: a2sh(short *restrict n, const char *s, char **restrict endp,
+@@ lib/atoi/a2i.h: a2sh_nc(short *restrict n, const char *s,
{
int status;
@@ lib/atoi/a2i.h: a2sh(short *restrict n, const char *s, char **restrict endp,
if (status != 0) {
errno = status;
return -1;
-@@ lib/atoi/a2i.h: a2si(int *restrict n, const char *s, char **restrict endp,
+@@ lib/atoi/a2i.h: a2si_nc(int *restrict n, const char *s,
{
int status;
@@ lib/atoi/a2i.h: a2si(int *restrict n, const char *s, char **restrict endp,
if (status != 0) {
errno = status;
return -1;
-@@ lib/atoi/a2i.h: a2sl(long *restrict n, const char *s, char **restrict endp,
+@@ lib/atoi/a2i.h: a2sl_nc(long *restrict n, const char *s,
{
int status;
@@ lib/atoi/a2i.h: a2sl(long *restrict n, const char *s, char **restrict endp,
if (status != 0) {
errno = status;
return -1;
-@@ lib/atoi/a2i.h: a2sll(long long *restrict n, const char *s, char **restrict endp,
+@@ lib/atoi/a2i.h: a2sll_nc(long long *restrict n, const char *s,
{
int status;
10: 158aa953 = 10: e1bdb655 src/usermod.c: Rename identifiers ralated to [ug]id's
11: 1392e7f3 = 11: ee13e401 src/usermod.c: Use id_t for parsing uid_t and gid_t
v2f changes:
$ git range-diff gh/getuh..gh/atoi getuh..atoi
1: caaa1ba1 = 1: 62e21a24 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE
2: a8d319da = 2: c993320f lib/idmapping.c: get_map_ranges(): Rename local variable
3: 8f69c62e = 3: d7186a5a lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls
4: f50f2349 = 4: 3efa3a4d lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
5: 647c70d7 = 5: 06d88123 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
6: 0b28e062 = 6: 962b4e45 lib/idmapping.c: get_map_ranges(): Remove dead code
7: 8bc60a8a = 7: 41adf242 lib/idmapping.c: get_map_ranges(): Simplify iterator variables
8: 439d8209 = 8: 36ff918f lib/idmapping.c: get_map_ranges(): Don't exit() from a library function
9: d709db6e = 9: 9f049eef lib/atoi/: Use libbsd's strto[iu](3bsd) when available
10: e1bdb655 = 10: cf609014 src/usermod.c: Rename identifiers ralated to [ug]id's
11: ee13e401 = 11: acc77934 src/usermod.c: Use id_t for parsing uid_t and gid_t
Looks good, but will unfortunately require some conflict resolution.
Ahhh, I'll rebase. Thanks!
@hallyn , I've rebased already. It's revision v5l
.
I've opened a Debian RFP for liba2i already, BTW:
v3
v3 changes: - Rebase ``` $ git range-diff gh/getuh..gh/atoi getuh..atoi 1: 62e21a24 = 1: 14ef2653 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: c993320f = 2: c4ad6a5d lib/idmapping.c: get_map_ranges(): Rename local variable 3: d7186a5a = 3: 212a171b lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: 3efa3a4d = 4: 8c0b20ed lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: 06d88123 = 5: 2b1b6da9 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 962b4e45 = 6: 7c20cbef lib/idmapping.c: get_map_ranges(): Remove dead code 7: 41adf242 = 7: 1c6e2418 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: 36ff918f = 8: 686d8de8 lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: 9f049eef ! 9: fa5581d1 lib/atoi/: Use libbsd's strto[iu](3bsd) when available @@ lib/atoi/a2i.h #include "atoi/strtoi.h" #include "atoi/strtou_noneg.h" -@@ lib/atoi/a2i.h: a2sh_nc(short *restrict n, const char *s, +@@ lib/atoi/a2i.h: a2sh_nc(short *restrict n, char *s, { int status; @@ lib/atoi/a2i.h: a2sh_nc(short *restrict n, const char *s, if (status != 0) { errno = status; return -1; -@@ lib/atoi/a2i.h: a2si_nc(int *restrict n, const char *s, +@@ lib/atoi/a2i.h: a2si_nc(int *restrict n, char *s, { int status; @@ lib/atoi/a2i.h: a2si_nc(int *restrict n, const char *s, if (status != 0) { errno = status; return -1; -@@ lib/atoi/a2i.h: a2sl_nc(long *restrict n, const char *s, +@@ lib/atoi/a2i.h: a2sl_nc(long *restrict n, char *s, { int status; @@ lib/atoi/a2i.h: a2sl_nc(long *restrict n, const char *s, if (status != 0) { errno = status; return -1; -@@ lib/atoi/a2i.h: a2sll_nc(long long *restrict n, const char *s, +@@ lib/atoi/a2i.h: a2sll_nc(long long *restrict n, char *s, { int status; 10: cf609014 = 10: 78104ba6 src/usermod.c: Rename identifiers ralated to [ug]id's 11: acc77934 = 11: 34d92c06 src/usermod.c: Use id_t for parsing uid_t and gid_t ```v4
v4 changes: - Rebase - Fix printf of id_t, by adding casts to uintmax_t and using %ju. ``` $ git range-diff gh/getuh..gh/atoi getuh..atoi 1: 14ef2653 = 1: 277a0e52 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: c4ad6a5d = 2: e097f630 lib/idmapping.c: get_map_ranges(): Rename local variable 3: 212a171b = 3: 90cdadbf lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: 8c0b20ed = 4: f6ac4bf6 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: 2b1b6da9 = 5: 7498a8b6 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 7c20cbef = 6: ebe7ce37 lib/idmapping.c: get_map_ranges(): Remove dead code 7: 1c6e2418 = 7: 03852427 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: 686d8de8 = 8: d8047a69 lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: fa5581d1 = 9: 32b0a816 lib/atoi/: Use libbsd's strto[iu](3bsd) when available 10: 78104ba6 ! 10: 8dc64f71 src/usermod.c: Rename identifiers ralated to [ug]id's @@ src/usermod.c: static int get_groups (char *list) +static struct id_range +getid_range(const char *str) { -- char *pos; +- const char *pos; - unsigned long first, last; - struct ulong_range result = { .first = ULONG_MAX, .last = 0 }; -+ char *pos; ++ const char *pos; + unsigned long first, last; + struct id_range result = { .first = ULONG_MAX, .last = 0 }; 11: 34d92c06 ! 11: d432ac27 src/usermod.c: Use id_t for parsing uid_t and gid_t @@ Commit message Use a static_assert(3) to make sure that id_t == uid_t == gid_t. + And use uintmax_t to print it, since on Linux they are unsigned types. + Link:v4b
- Rebase ``` $ git range-diff gh/getuh..gh/atoi getuh..atoi 1: 277a0e52 = 1: 776c3711 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: e097f630 = 2: 3e0ac255 lib/idmapping.c: get_map_ranges(): Rename local variable 3: 90cdadbf = 3: f1512ea1 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: f6ac4bf6 = 4: 4a7d0d3d lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: 7498a8b6 = 5: 7bc521cc lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: ebe7ce37 = 6: 0618c66e lib/idmapping.c: get_map_ranges(): Remove dead code 7: 03852427 = 7: ffb55677 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: d8047a69 = 8: f9ac734b lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: 32b0a816 = 9: fe80f69a lib/atoi/: Use libbsd's strto[iu](3bsd) when available 10: 8dc64f71 = 10: e0a4502c src/usermod.c: Rename identifiers ralated to [ug]id's 11: d432ac27 = 11: b531af95 src/usermod.c: Use id_t for parsing uid_t and gid_t ```v4c
- Rebase ``` $ git range-diff gh/getuh..gh/atoi getuh..atoi 1: 776c3711 = 1: b8cbe5c8 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: 3e0ac255 = 2: 8ecab761 lib/idmapping.c: get_map_ranges(): Rename local variable 3: f1512ea1 = 3: c51482f1 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: 4a7d0d3d = 4: 4f694b04 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: 7bc521cc = 5: c8e2796d lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 0618c66e = 6: fb31a081 lib/idmapping.c: get_map_ranges(): Remove dead code 7: ffb55677 = 7: edf3b099 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: f9ac734b = 8: 7754af30 lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: fe80f69a = 9: 31560fdd lib/atoi/: Use libbsd's strto[iu](3bsd) when available 10: e0a4502c = 10: a141e80e src/usermod.c: Rename identifiers ralated to [ug]id's 11: b531af95 = 11: c3076ea5 src/usermod.c: Use id_t for parsing uid_t and gid_t ```v4d
- Rebase ``` $ git range-diff gh/getuh..gh/atoi getuh..atoi 1: b8cbe5c8 = 1: 848aabf9 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: 8ecab761 = 2: 57e44e82 lib/idmapping.c: get_map_ranges(): Rename local variable 3: c51482f1 = 3: d74b29b1 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: 4f694b04 = 4: 89d3f3a3 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: c8e2796d = 5: 71d25538 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: fb31a081 = 6: 0a519115 lib/idmapping.c: get_map_ranges(): Remove dead code 7: edf3b099 = 7: 539adc20 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: 7754af30 = 8: 316f0c9c lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: 31560fdd = 9: 5c302c4f lib/atoi/: Use libbsd's strto[iu](3bsd) when available 10: a141e80e = 10: ddf63b19 src/usermod.c: Rename identifiers ralated to [ug]id's 11: c3076ea5 = 11: 7d933c74 src/usermod.c: Use id_t for parsing uid_t and gid_t ```v4e
- Rebase ``` $ git range-diff gh/getuh..gh/atoi getuh..atoi 1: 848aabf9 = 1: 41cb4d0e lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: 57e44e82 = 2: f477b220 lib/idmapping.c: get_map_ranges(): Rename local variable 3: d74b29b1 = 3: 0bd955ea lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: 89d3f3a3 = 4: 0c323552 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: 71d25538 = 5: 473ea791 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 0a519115 = 6: a16bc9c2 lib/idmapping.c: get_map_ranges(): Remove dead code 7: 539adc20 = 7: c09e6b77 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: 316f0c9c = 8: 59bdbd2c lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: 5c302c4f = 9: f2512a29 lib/atoi/: Use libbsd's strto[iu](3bsd) when available 10: ddf63b19 = 10: e7045798 src/usermod.c: Rename identifiers ralated to [ug]id's 11: 7d933c74 = 11: d87c576a src/usermod.c: Use id_t for parsing uid_t and gid_t ```v5
- Rebase - Don't use libbsd's strto[iu](3bsd). - Split files (as done in liba2i). This makes the source code significantly more readable. - Correctly handle a (invalid) base of 1. ``` $ git range-diff 41cb4d0e^..gh/atoi getuh..atoi 1: 41cb4d0e = 1: fbc841bf lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: f477b220 = 2: b0aa86fd lib/idmapping.c: get_map_ranges(): Rename local variable 3: 0bd955ea = 3: cbed21fe lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: 0c323552 = 4: 768c69f2 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: 473ea791 = 5: 22a0534f lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: a16bc9c2 = 6: 730d321c lib/idmapping.c: get_map_ranges(): Remove dead code 7: c09e6b77 = 7: a1bfbff5 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: 59bdbd2c = 8: 653efe3c lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: f2512a29 < -: -------- lib/atoi/: Use libbsd's strto[iu](3bsd) when available 10: e7045798 = 9: 44fb001d src/usermod.c: Rename identifiers ralated to [ug]id's 11: d87c576a = 10: 669222c1 src/usermod.c: Use id_t for parsing uid_t and gid_t -: -------- > 11: c5dbe653 lib/atoi/, *: Split files -: -------- > 12: 4232f065 lib/atoi/strtoi/, tests/: strto[iu]_(): 1 is an invalid base ```v5b
- Fix spurious backslash from v5. ``` $ git range-diff getuh gh/atoi atoi 1: fbc841bf = 1: fbc841bf lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: b0aa86fd = 2: b0aa86fd lib/idmapping.c: get_map_ranges(): Rename local variable 3: cbed21fe = 3: cbed21fe lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: 768c69f2 = 4: 768c69f2 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: 22a0534f = 5: 22a0534f lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 730d321c = 6: 730d321c lib/idmapping.c: get_map_ranges(): Remove dead code 7: a1bfbff5 = 7: a1bfbff5 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: 653efe3c = 8: 653efe3c lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: 44fb001d = 9: 44fb001d src/usermod.c: Rename identifiers ralated to [ug]id's 10: 669222c1 = 10: 669222c1 src/usermod.c: Use id_t for parsing uid_t and gid_t 11: c5dbe653 ! 11: d732c335 lib/atoi/, *: Split files @@ lib/atoi/strtoi/strtoi.h (new) + + if (base != 0 && (base < 0 || base > 36)) { + *status = EINVAL; -+ return MAX(min, MIN(max, 0)); \ ++ return MAX(min, MIN(max, 0)); + } + + e = errno; 12: 4232f065 ! 12: 617dae99 lib/atoi/strtoi/, tests/: strto[iu]_(): 1 is an invalid base @@ lib/atoi/strtoi/strtoi.h: strtoi_(const char *s, char **restrict endp, int base, - if (base != 0 && (base < 0 || base > 36)) { + if (base != 0 && (base < 2 || base > 36)) { *status = EINVAL; - return MAX(min, MIN(max, 0)); \ + return MAX(min, MIN(max, 0)); } ## lib/atoi/strtoi/strtou.h ## ```v5c
- Update tests/unit/Makefile.am ``` $ git range-diff getuh gh/atoi atoi 1: fbc841bf = 1: fbc841bf lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: b0aa86fd = 2: b0aa86fd lib/idmapping.c: get_map_ranges(): Rename local variable 3: cbed21fe = 3: cbed21fe lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: 768c69f2 = 4: 768c69f2 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: 22a0534f = 5: 22a0534f lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 730d321c = 6: 730d321c lib/idmapping.c: get_map_ranges(): Remove dead code 7: a1bfbff5 = 7: a1bfbff5 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: 653efe3c = 8: 653efe3c lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: 44fb001d = 9: 44fb001d src/usermod.c: Rename identifiers ralated to [ug]id's 10: 669222c1 = 10: 669222c1 src/usermod.c: Use id_t for parsing uid_t and gid_t 11: d732c335 ! 11: 91dba81a lib/atoi/, *: Split files @@ src/usermod.c #include "chkname.h" #include "defines.h" + ## tests/unit/Makefile.am ## +@@ tests/unit/Makefile.am: test_adds_LDADD = \ + $(NULL) + + test_atoi_strtoi_SOURCES = \ +- ../../lib/atoi/strtoi.c \ ++ ../../lib/atoi/strtoi/strtoi.c \ ++ ../../lib/atoi/strtoi/strtou_noneg.c \ + test_atoi_strtoi.c \ + $(NULL) + test_atoi_strtoi_CFLAGS = \ + ## tests/unit/test_atoi_strtoi.c ## @@ #includev5d
- Rebase ``` $ git range-diff gh/getuh..gh/atoi getuh..atoi 1: fbc841bf = 1: 64c467db lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: b0aa86fd = 2: 0097ffca lib/idmapping.c: get_map_ranges(): Rename local variable 3: cbed21fe ! 3: 355d155e lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls @@ Commit message ## lib/idmapping.c ## @@ - #includev5e
- Rebase ``` $ git range-diff gh/getuh..gh/atoi getuh..atoi 1: 64c467db = 1: cd2ef3b8 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: 0097ffca = 2: 4a49bf15 lib/idmapping.c: get_map_ranges(): Rename local variable 3: 355d155e = 3: 552bbc7c lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: 458529a6 = 4: 0101cd40 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: 5a931902 = 5: 454e5b5a lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 061c01db = 6: 45428cb0 lib/idmapping.c: get_map_ranges(): Remove dead code 7: 35b331f2 = 7: 9cafbca8 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: 94197721 = 8: c75f6b7e lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: 72cfdaee = 9: 18808c4d src/usermod.c: Rename identifiers ralated to [ug]id's 10: 50ddb11d = 10: 430e1f41 src/usermod.c: Use id_t for parsing uid_t and gid_t 11: 4b4d6e6d = 11: 13ac46d0 lib/atoi/, *: Split files 12: f556e79f = 12: 5cbcfbad lib/atoi/strtoi/, tests/: strto[iu]_(): 1 is an invalid base ```v5f
- Rebase ``` $ git range-diff gh/getuh..gh/atoi shadow/master..atoi 1: cd2ef3b8 = 1: 8eca57a8 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: 4a49bf15 = 2: 7f92e2fe lib/idmapping.c: get_map_ranges(): Rename local variable 3: 552bbc7c = 3: 42811113 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: 0101cd40 = 4: ee1b4201 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: 454e5b5a = 5: b129cf43 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 45428cb0 = 6: 769a1256 lib/idmapping.c: get_map_ranges(): Remove dead code 7: 9cafbca8 = 7: 8f1b2eb0 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: c75f6b7e = 8: cbf4ecdd lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: 18808c4d = 9: 2f870735 src/usermod.c: Rename identifiers ralated to [ug]id's 10: 430e1f41 = 10: e9623cd9 src/usermod.c: Use id_t for parsing uid_t and gid_t 11: 13ac46d0 = 11: 0f2e0345 lib/atoi/, *: Split files 12: 5cbcfbad = 12: 14c5d2af lib/atoi/strtoi/, tests/: strto[iu]_(): 1 is an invalid base ```v5g
- Fix includes ``` $ git range-diff shadow/master gh/atoi atoi 1: 8eca57a8 = 1: 8eca57a8 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: 7f92e2fe = 2: 7f92e2fe lib/idmapping.c: get_map_ranges(): Rename local variable 3: 42811113 = 3: 42811113 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: ee1b4201 = 4: ee1b4201 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: b129cf43 = 5: b129cf43 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 769a1256 = 6: 769a1256 lib/idmapping.c: get_map_ranges(): Remove dead code 7: 8f1b2eb0 = 7: 8f1b2eb0 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: cbf4ecdd = 8: cbf4ecdd lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: 2f870735 = 9: 2f870735 src/usermod.c: Rename identifiers ralated to [ug]id's 10: e9623cd9 = 10: e9623cd9 src/usermod.c: Use id_t for parsing uid_t and gid_t 11: 0f2e0345 ! 11: 63fab302 lib/atoi/, *: Split files @@ lib/atoi/a2i/a2i.h (new) +#includev5h
- Rebase ``` $ git range-diff alx/master..gh/atoi shadow/master..atoi 1: 8eca57a8 = 1: ee6c7a50 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: 7f92e2fe = 2: 65207ea0 lib/idmapping.c: get_map_ranges(): Rename local variable 3: 42811113 = 3: 45419031 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: ee1b4201 = 4: 79de0d1d lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: b129cf43 = 5: e6b93289 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 769a1256 = 6: 14a5f273 lib/idmapping.c: get_map_ranges(): Remove dead code 7: 8f1b2eb0 = 7: 944e349f lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: cbf4ecdd = 8: f351cd8c lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: 2f870735 = 9: ead9a69a src/usermod.c: Rename identifiers ralated to [ug]id's 10: e9623cd9 = 10: 5e46e4bb src/usermod.c: Use id_t for parsing uid_t and gid_t 11: 63fab302 = 11: 198759f5 lib/atoi/, *: Split files 12: cf44729d = 12: 034820cf lib/atoi/strtoi/, tests/: strto[iu]_(): 1 is an invalid base ```v5i
- Rebase ``` $ git range-diff master..gh/atoi shadow/master..atoi 1: ee6c7a50 = 1: fd2e376b lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: 65207ea0 = 2: 830197f9 lib/idmapping.c: get_map_ranges(): Rename local variable 3: 45419031 = 3: fd3b537e lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: 79de0d1d = 4: 8dad1527 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: e6b93289 = 5: f8d4d21e lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 14a5f273 = 6: 9812b53d lib/idmapping.c: get_map_ranges(): Remove dead code 7: 944e349f = 7: 3dbf308a lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: f351cd8c = 8: c8b96f53 lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: ead9a69a = 9: b014cb15 src/usermod.c: Rename identifiers ralated to [ug]id's 10: 5e46e4bb = 10: 2917eff2 src/usermod.c: Use id_t for parsing uid_t and gid_t 11: 198759f5 = 11: f16725dd lib/atoi/, *: Split files 12: 034820cf = 12: 6d0f61f6 lib/atoi/strtoi/, tests/: strto[iu]_(): 1 is an invalid base ```v5j
- Remove unused includes. ``` $ git range-diff shadow/master gh/atoi atoi 1: fd2e376b = 1: fd2e376b lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: 830197f9 = 2: 830197f9 lib/idmapping.c: get_map_ranges(): Rename local variable 3: fd3b537e = 3: fd3b537e lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: 8dad1527 = 4: 8dad1527 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: f8d4d21e = 5: f8d4d21e lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 9812b53d = 6: 9812b53d lib/idmapping.c: get_map_ranges(): Remove dead code 7: 3dbf308a = 7: 3dbf308a lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: c8b96f53 = 8: c8b96f53 lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: b014cb15 = 9: b014cb15 src/usermod.c: Rename identifiers ralated to [ug]id's 10: 2917eff2 = 10: 2917eff2 src/usermod.c: Use id_t for parsing uid_t and gid_t 11: f16725dd ! 11: 2283be7d lib/atoi/, *: Split files @@ lib/atoi/a2i/a2i.h (new) + +#includev5k
- Rebase - Reviewed-by: @tych0 ``` $ git range-diff master..gh/atoi shadow/master..atoi 1: fd2e376b = 1: 4264590d lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: 830197f9 = 2: 87669018 lib/idmapping.c: get_map_ranges(): Rename local variable 3: fd3b537e = 3: bcb352b7 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: 8dad1527 = 4: f4794071 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: f8d4d21e = 5: a1f01c63 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 9812b53d = 6: 5c567611 lib/idmapping.c: get_map_ranges(): Remove dead code 7: 3dbf308a = 7: ef4ce530 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: c8b96f53 = 8: b3dcad1b lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: b014cb15 = 9: dd0e3fe2 src/usermod.c: Rename identifiers ralated to [ug]id's 10: 2917eff2 ! 10: dacfe210 src/usermod.c: Use id_t for parsing uid_t and gid_t @@ Commit message And use uintmax_t to print it, since on Linux they are unsigned types. Link:v5l
- Rebase ``` $ git range-diff gh/master..gh/atoi shadow/master..atoi 1: 4264590d = 1: 61baea54 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE 2: 87669018 = 2: ec8eb105 lib/idmapping.c: get_map_ranges(): Rename local variable 3: bcb352b7 = 3: 9160cf67 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls 4: f4794071 = 4: 78fdec8f lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 5: a1f01c63 = 5: 7397fb93 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call 6: 5c567611 = 6: 7964c176 lib/idmapping.c: get_map_ranges(): Remove dead code 7: ef4ce530 = 7: 407db4a6 lib/idmapping.c: get_map_ranges(): Simplify iterator variables 8: b3dcad1b = 8: dac13a74 lib/idmapping.c: get_map_ranges(): Don't exit() from a library function 9: dd0e3fe2 = 9: 55ef2c4f src/usermod.c: Rename identifiers ralated to [ug]id's 10: dacfe210 = 10: 65651a4c src/usermod.c: Use id_t for parsing uid_t and gid_t 11: 8c75db71 ! 11: f0a13167 lib/atoi/, *: Split files @@ lib/sgetspent.c -#include "atoi/str2i.h" +#include "atoi/a2i/a2s.h" +#include "atoi/str2i/str2u.h" + #include "defines.h" #include "prototypes.h" #include "shadowlog_internal.h" - #include "defines.h" ## lib/shadow.c ## @@ @@ lib/shadow.c +#include "atoi/str2i/str2u.h" #include "defines.h" #include "prototypes.h" - + #include "string/strtok/stpsep.h" ## lib/strtoday.c ## @@ 12: 97ab87df = 12: 2532af65 lib/atoi/strtoi/, tests/: strto[iu]_(): 1 is an invalid base ```