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

Fix compiler warnings, part 10 #1395

Merged
merged 1 commit into from
Mar 8, 2021

Conversation

nilason
Copy link
Contributor

@nilason nilason commented Feb 21, 2021

Remove argument not used by format string
Fixes -Wformat-extra-args compiler warnings.

This was originally part of #1274, but separated in hope for finding a better solution.

Tenth part addressing #1247.

Compiler warning:

main.c:166:30: warning: data argument not used by format string [-Wformat-extra-args]
                             WEIGHTS[i][j]);
                             ^

The removed 'if' condition was never true and the faulty use
of snprintf was never reached.
@nilason nilason marked this pull request as ready for review February 22, 2021 08:18
@nilason nilason changed the title WIP: Fix compiler warnings, part 10 Fix compiler warnings, part 10 Feb 22, 2021
@nilason
Copy link
Contributor Author

nilason commented Feb 22, 2021

I prefer to keep this code active as long as there is a reason to test for if (WEIGHTS[i][j] != -1.0)

Originally posted by @metzm in #1274 (comment)

I think you perhaps misread the code. By design WEIGHTS[i][j] may be -1.0 if map units is used (with -m flag) printed with ......:

If the distance is given in map units (flag <tt>-m</tt>), then the
search window can be modeled more accurately as a circle. The
illustration below shows the precomputed weights for a distance in map
units that is approximately equivalent to four cells from the center
cell:
<pre>
...... ...... ...... 000.00 000.00 000.00 ...... ...... ......
...... 000.00 000.02 000.06 000.09 000.06 000.02 000.00 ......
...... 000.02 000.11 000.22 000.28 000.22 000.11 000.02 ......
000.00 000.07 000.22 000.44 000.58 000.44 000.22 000.07 000.00

However, that part doesn't affect the troublesome snprintf call and its own if condition.

if (WEIGHTS[i][j] != -1.0) {
snprintf(weight_matrix_weight_buf, weight_matrix_line_length,
"%06.2f ", WEIGHTS[i][j]);
if (strlen(weight_matrix_weight_buf) >
(weight_matrix_weight_length)) {
snprintf(weight_matrix_weight_buf,
weight_matrix_line_length, "[????] ",
WEIGHTS[i][j]);
}
}
else {
snprintf(weight_matrix_weight_buf, weight_matrix_line_length,
"...... ");
}

The if condition on line 162-163 can by definition never be true, as the size of weight_matrix_weight_buf is set to weight_matrix_weight_length + 1.

I'm quite confident now this is dead code (L162-167) which can be removed all together. Pushed changes according to this.

@nilason nilason requested a review from metzm February 22, 2021 08:49
Copy link
Contributor

@metzm metzm left a comment

Choose a reason for hiding this comment

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

The variable weight_matrix_weight_length needs to be removed in a separate PR.

@nilason nilason merged commit 3167aa8 into OSGeo:master Mar 8, 2021
@nilason
Copy link
Contributor Author

nilason commented Mar 8, 2021

@metzm Thanks!

@nilason nilason deleted the fix-compiler-warnings-10 branch March 11, 2021 19:56
marisn pushed a commit to marisn/grass that referenced this pull request Mar 22, 2021
The removed 'if' condition was never true and the faulty use
of snprintf was never reached.
@neteler neteler added this to the 8.0.0 milestone Dec 9, 2021
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
The removed 'if' condition was never true and the faulty use
of snprintf was never reached.
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
The removed 'if' condition was never true and the faulty use
of snprintf was never reached.
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

3 participants