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

Eliminate uses of non-threadsafe locatime() and ctime() functions #921

Merged
merged 3 commits into from Oct 31, 2019

Conversation

pmatilai
Copy link
Member

LGTM pointed out localtime() and ctime() are not thread-safe, and additionally ctime() is considered obsolete since POSIX.1-2008. Replace with localtime_r() and strftime() instead.

Long broken --prtpkts debug switch is fixed in a separate commit to have means of testing the strftime() change.

Move the _print_pkts global to librpmio where the two relevant users
can actually access it, and make them use it. This has been broken
for years...
LGTM flags localtime() as a "dangerous" function, which seems a bit
over the top to me, but as we're flirting with threads, it certainly
is not thread-safe.
POSIX.1-2008 marked ctime() as obsolete and recommends strftime() instead.
We get two flies on one stroke as ctime() is also classified "dangerous"
by LGTM due to not being thread-safe.

strftime(..., "%c"...) isn't exactly the same as ctime() but is consistent
with what we use elsewhere and sufficient for debug purposes anyway.
@lgtm-com
Copy link

lgtm-com bot commented Oct 31, 2019

This pull request fixes 4 alerts when merging 72b1772 into 63930cd - view on LGTM.com

fixed alerts:

  • 4 for Use of potentially dangerous function

@ffesti ffesti merged commit 998b516 into rpm-software-management:master Oct 31, 2019
@pmatilai pmatilai deleted the timer-pr branch November 4, 2019 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants