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(), replacing them by a2i() calls #895

Open
wants to merge 4 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
v3b
  • Rebase
$ git range-diff 44bf6f3b^..gh/rm_noneg shadow/master..rm_noneg 
1:  44bf6f3b = 1:  7de6994c lib/gettime.c: gettime(): Call a2i() instead of strtoull_noneg()
2:  4070b87d = 2:  1ade434f lib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused function
3:  5ba384e6 = 3:  ca8d63c0 src/check_subid_range.c: Call str2ul() instead of strtoul_noneg()
4:  80ad37bc = 4:  110447bb lib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused function
v3c
  • Reword error message
$ git range-diff shadow/master gh/rm_noneg rm_noneg 
1:  7de6994c ! 1:  368df2d2 lib/gettime.c: gettime(): Call a2i() instead of strtoull_noneg()
    @@ lib/gettime.c
     -          return epoch;
     +  if (a2i(time_t, &epoch, source_date_epoch, NULL, 10, 0, fallback) == -1) {
     +          fprintf(shadow_logfd,
    -+                  _("Environment variable $SOURCE_DATE_EPOCH: strtoi(\"%s\"): %s"),
    ++                  _("Environment variable $SOURCE_DATE_EPOCH: a2i(\"%s\"): %s"),
     +                  source_date_epoch, strerror(errno));
     +          return fallback;
        }
2:  1ade434f = 2:  7e8aa6e1 lib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused function
3:  ca8d63c0 = 3:  ce1c306b src/check_subid_range.c: Call str2ul() instead of strtoul_noneg()
4:  110447bb = 4:  fbe6d9bf 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

@alejandro-colomar
Copy link
Collaborator Author

@lamby
We've merge all the PRs that were dependencies of this one, so I expect this to be merged soon. This one includes the fix for the problems we discussed.

@alejandro-colomar alejandro-colomar changed the title Remove strtou[l]l_noneg(), as they've been replaced by a2i() calls Remove strtou[l]l_noneg(), replacing them by a2i() calls May 17, 2024
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 <[email protected]>
Cc: Serge Hallyn <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
…unction

All call sites were replaced by a2i() recently.

Signed-off-by: Alejandro Colomar <[email protected]>
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 <[email protected]>
…nction

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

Signed-off-by: Alejandro Colomar <[email protected]>
} else {
/* Valid */
return epoch;
if (a2i(time_t, &epoch, source_date_epoch, NULL, 10, 0, fallback) == -1) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lamby Should we accept negative values? Why did this use strtoull(1) originally?

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