Skip to content

MAINT: Fix LGTM.com warning: Comparison result is always the same (res)#19944

Merged
charris merged 1 commit into
numpy:mainfrom
DimitriPapadopoulos:lgtm_warning_PyArray_CopyAsFlat
Sep 24, 2021
Merged

MAINT: Fix LGTM.com warning: Comparison result is always the same (res)#19944
charris merged 1 commit into
numpy:mainfrom
DimitriPapadopoulos:lgtm_warning_PyArray_CopyAsFlat

Conversation

@DimitriPapadopoulos

Copy link
Copy Markdown
Contributor

Comparison result is always the same
Comparison is always false because res <= 0.

https://lgtm.com/projects/g/numpy/numpy/snapshot/6fd377657ac7fcc9d244e2d1ebae26e70f60db51/files/numpy/core/src/multiarray/ctors.c?sort=name&dir=ASC&mode=heatmap#xa080a7fcc79c74e4:1

Indeed the for(;;) loop may stop on 3 different breaks:

            res = -1;
            break;
            if (!res) {
                break;
            if (!res) {
                break;

Therefore, after the loop, the only possible values for res are -1 and 0, and (res > 0) is always false.

This originates in 37dc69c (#17029).

@DimitriPapadopoulos DimitriPapadopoulos changed the title MAINT: Fix LGTM.com warning MAINT: Fix LGTM.com warning: Comparison result is always the same Sep 24, 2021
@DimitriPapadopoulos DimitriPapadopoulos changed the title MAINT: Fix LGTM.com warning: Comparison result is always the same MAINT: Fix LGTM.com warning: Comparison result is always the same (res) Sep 24, 2021
@charris

charris commented Sep 24, 2021

Copy link
Copy Markdown
Member

This might be clearer if res == 0 was used instead of !res.

Comparison result is always the same
Comparison is always false because res <= 0.

Indeed the for(;;) iteration may stop on 3 different breaks:

            res = -1;
            break;

            if (!res) {
                break;

            if (!res) {
                break;

Therefore, after the loop, the only possible values for res are -1 and 0,
and (res > 0) is always false.

This originates in 37dc69c (numpy#17029).
@DimitriPapadopoulos DimitriPapadopoulos force-pushed the lgtm_warning_PyArray_CopyAsFlat branch from 47da8f8 to 580bbdf Compare September 24, 2021 17:06
@DimitriPapadopoulos

Copy link
Copy Markdown
Contributor Author

Clearer indeed. Changed to res == 0.

@charris charris merged commit 3899d9c into numpy:main Sep 24, 2021
@charris

charris commented Sep 24, 2021

Copy link
Copy Markdown
Member

Thanks @DimitriPapadopoulos .

@DimitriPapadopoulos DimitriPapadopoulos deleted the lgtm_warning_PyArray_CopyAsFlat branch September 24, 2021 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants