Skip to content

gh-104040: Silence a "comparison is always false" warning#104043

Closed
TabLand wants to merge 8 commits into
python:mainfrom
TabLand:fix-issue-104040
Closed

gh-104040: Silence a "comparison is always false" warning#104043
TabLand wants to merge 8 commits into
python:mainfrom
TabLand:fix-issue-104040

Conversation

@TabLand

@TabLand TabLand commented May 1, 2023

Copy link
Copy Markdown
Contributor

On i686 by clarifying datatype used in check_ticks_per_second

On i686 by clarifying datatype used in check_ticks_per_second
@arhadthedev arhadthedev added the build The build process and cross-build label May 3, 2023

@abalkin abalkin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@TabLand

TabLand commented Jul 8, 2023

Copy link
Copy Markdown
Contributor Author

Hi @pganssle,
Appreciate you're busy,
Would it be possible to review this when you get some extra bandwidth?

@TabLand

TabLand commented Oct 3, 2023

Copy link
Copy Markdown
Contributor Author

Hi @abalkin / @arhadthedev,
Would it be possible to request a different 2nd reviewer?
Perhaps @vstinner?

@abalkin abalkin requested a review from vstinner October 3, 2023 08:17
@abalkin abalkin enabled auto-merge (squash) October 3, 2023 09:25
Comment thread Modules/timemodule.c
cannot overflow. */
if (tps >= 0 && (_PyTime_t)tps > _PyTime_MAX / SEC_TO_NS) {
_PyTime_t max_time_in_seconds = _PyTime_MAX / SEC_TO_NS;
if (tps >= 0 && (_PyTime_t)tps > max_time_in_seconds) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I dislike this fix. You should use LONG_MAX and the preprocessor instead, something like:

#ifdef LONG_MAX >= _PyTime_MAX
if (...)
#endif

The compiler is correct that with 32-bit long (which is the case on Windows 64-bit), the condition is always false:

$ python
>>> SEC_TO_NS = 10**9
# _PyTime_t is always signed 64-bit
>>> _PyTime_MAX=2**63-1

# 64-bit signed long
>>> LONG_MAX=2**63-1
>>> LONG_MAX > (_PyTime_MAX // SEC_TO_NS)
True

# 32-bit long
>>> LONG_MAX=2**31-1
>>> LONG_MAX > (_PyTime_MAX // SEC_TO_NS)
False

@TabLand

TabLand commented Dec 3, 2023

Copy link
Copy Markdown
Contributor Author

Hi @vstinner,

Apologies for the delay.

It looks like the recent reworking you've done on the timemodule.c file now makes this pull request obsolete.

Many thanks for your efforts 🙂️

@TabLand TabLand closed this Dec 3, 2023
auto-merge was automatically disabled December 3, 2023 17:54

Pull request was closed

@vstinner

vstinner commented Dec 4, 2023

Copy link
Copy Markdown
Member

It looks like the recent reworking you've done on the timemodule.c file now makes this pull request obsolete.

Oh, right. I just removed the check. IMO it's no longer needed.

Thanks for your PR anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge build The build process and cross-build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants