Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove strtou[l]l_noneg(), as they've been replaced by a2i() calls #895

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Jan 9, 2024


Revisions:

v3 v3 changes:
  • Rebase
$ git range-diff 851315ea^..gh/rm_noneg getrange..rm_noneg 
1:  851315ea = 1:  44bf6f3b lib/gettime.c: gettime(): Call a2i() instead of strtoull_noneg()
2:  3c3d2bb9 = 2:  4070b87d lib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused function
3:  dc774cda = 3:  5ba384e6 src/check_subid_range.c: Call str2ul() instead of strtoul_noneg()
4:  857f2e9f = 4:  80ad37bc lib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused function

@alejandro-colomar alejandro-colomar changed the title Remove strtou[l]l_noneg(), as they've been replaced by getlong() variants Remove strtou[l]l_noneg(), as they've been replaced by a2i() variants Jan 17, 2024
@alejandro-colomar alejandro-colomar changed the title Remove strtou[l]l_noneg(), as they've been replaced by a2i() variants Remove strtou[l]l_noneg(), as they've been replaced by a2i() calls Jan 17, 2024
@alejandro-colomar
Copy link
Collaborator Author

v2 changes:

  • Rebase to master
$ git range-diff gh/getrange..gh/rm_noneg getrange..rm_noneg 
1:  9f8efae5 = 1:  e8aadb9c lib/gettime.c: gettime(): Call a2i() instead of strtoull_noneg()
2:  22b425f8 = 2:  80f9e237 lib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused function
3:  eb1c2eaf = 3:  5959165f src/check_subid_range.c: Call str2ul() instead of strtoul_noneg()
4:  b23f9c03 = 4:  4c751792 lib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused function

@alejandro-colomar
Copy link
Collaborator Author

v2b changes:

  • Rebase on master
$ git range-diff gh/getrange..gh/rm_noneg getrange..rm_noneg 
1:  e8aadb9c = 1:  9ecdce44 lib/gettime.c: gettime(): Call a2i() instead of strtoull_noneg()
2:  80f9e237 = 2:  f71fbb3c lib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused function
3:  5959165f = 3:  28ace782 src/check_subid_range.c: Call str2ul() instead of strtoul_noneg()
4:  4c751792 = 4:  096cce6a lib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused function

@alejandro-colomar
Copy link
Collaborator Author

v2c changes:

  • Rebase on master
$ git range-diff gh/getrange..gh/rm_noneg getrange..rm_noneg 
1:  9ecdce44 = 1:  adaf6782 lib/gettime.c: gettime(): Call a2i() instead of strtoull_noneg()
2:  f71fbb3c = 2:  870b9eb5 lib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused function
3:  28ace782 = 3:  669e57b8 src/check_subid_range.c: Call str2ul() instead of strtoul_noneg()
4:  096cce6a = 4:  8fb1abfd lib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused function

@alejandro-colomar
Copy link
Collaborator Author

v2d changes:

  • Rebase on master
$ git range-diff gh/getrange..gh/rm_noneg getrange..rm_noneg 
1:  adaf6782 = 1:  e63f5270 lib/gettime.c: gettime(): Call a2i() instead of strtoull_noneg()
2:  870b9eb5 = 2:  f52712c2 lib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused function
3:  669e57b8 = 3:  12d987fb src/check_subid_range.c: Call str2ul() instead of strtoul_noneg()
4:  8fb1abfd = 4:  07e26fe7 lib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused function

@alejandro-colomar
Copy link
Collaborator Author

v2e changes:

  • Rebase
$ git range-diff e63f5270^..gh/rm_noneg getrange..rm_noneg 
1:  e63f5270 = 1:  940e0993 lib/gettime.c: gettime(): Call a2i() instead of strtoull_noneg()
2:  f52712c2 = 2:  728c5f45 lib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused function
3:  12d987fb = 3:  014f107e src/check_subid_range.c: Call str2ul() instead of strtoul_noneg()
4:  07e26fe7 = 4:  eb1290de lib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused function

@alejandro-colomar

This comment was marked as resolved.

@alejandro-colomar
Copy link
Collaborator Author

v2f changes:

  • Rebase (the problem has been workarounded in getrange).
$ git range-diff gh/getrange..gh/rm_noneg getrange..rm_noneg 
1:  940e0993 = 1:  851315ea lib/gettime.c: gettime(): Call a2i() instead of strtoull_noneg()
2:  728c5f45 = 2:  3c3d2bb9 lib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused function
3:  014f107e = 3:  dc774cda src/check_subid_range.c: Call str2ul() instead of strtoul_noneg()
4:  eb1290de = 4:  857f2e9f lib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused function

These overloaded macros allow passing either a const or a non-const
endp, and will call the appropriate function.  This kind of const
overloading has prior art in C23's string functions, such as memchr(3).

Martin suggested using an artificial function pointer in _Generic(3); it
allows switching on various types at the same time.

Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf#subsubsection.7.26.5.2>
Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114731>
Co-developed-by: Martin Uecker <muecker@gwdg.de>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
It simplifies the error checking.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Now that we have const-generic macros, we can use a const pointer.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
isdigit(3) requires a cast if the argument is of type 'char'.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
time_t isn't necessarily unsigned (in fact, it's likely to be signed.
Therefore, parse the number as the right type, via a2i(time_t, ...).

Still, reject negative numbers, just to be cautious.  It was done
before (strtoull_noneg()), so it shouldn't be a problem.  (However,
strtoull_noneg() was only introduced recently, and before that we called
strtoull(3), which silently accepted negative values.)

Remove the limitation of ULONG_MAX, which seems arbitrary.  It probably
was written in times where 'time_t' had the same length of 'long', and
this was thus a test that the value didn't overflow 'time_t'.  Such a
test is implicit in the a2i() call, so forget about it.

Unify the error messages into a single one that provides all the info
(except the value of 'fallback').

Link: <shadow-maint@cb610d5#r136407772>
Cc: Chris Lamb <lamby@debian.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
…unction

All call sites were replaced by a2i() recently.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
It is a simpler call, with more type safety.

A consequence of this change is that the program now accepts numbers in
bases 8 and 16.  That's not a problem here, I think.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
…nction

All call sites have been replaced by functions from "atoi/a2i.h" and
"atoi/str2i.h" recently.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant