Skip to content

test_simple: cast to avoid -Wsign-conversion (clang-tidy) - #2418

Closed
vszakats wants to merge 3 commits into
libssh2:masterfrom
vszakats:t-libgcrypt-sign
Closed

vszakats wants to merge 3 commits into
libssh2:masterfrom
vszakats:t-libgcrypt-sign

Conversation

@vszakats

@vszakats vszakats commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

Fixing:

tests/test_simple.c:84:56: error: operand of ? changes signedness: 'int' to 'unsigned long' [clang-diagnostic-sign-conversion]
   84 |         gcry_mpi_t f = gcry_mpi_set_ui(NULL, fi >= 0 ? fi : -fi);
      |                        ~~~~~~~~~~~~~~~                 ^~
tests/test_simple.c:84:61: error: operand of ? changes signedness: 'int' to 'unsigned long' [clang-diagnostic-sign-conversion]
   84 |         gcry_mpi_t f = gcry_mpi_set_ui(NULL, fi >= 0 ? fi : -fi);
      |                        ~~~~~~~~~~~~~~~                      ^~~
tests/test_simple.c:85:46: error: implicit conversion changes signedness: 'int' to 'unsigned long' [clang-diagnostic-sign-conversion]
   85 |         gcry_mpi_t p = gcry_mpi_set_ui(NULL, atoi(tests[i].p));
      |                        ~~~~~~~~~~~~~~~       ^~~~~~~~~~~~~~~~

Ref: https://github.com/libssh2/libssh2/actions/runs/30043871895/job/89330114459#step:24:124

Also add intermediate current test holder var to keep code readable.

Follow-up to 76d30e5 #2417
Follow-up to fcf8307 #2239

```
tests/test_simple.c:84:56: error: operand of ? changes signedness: 'int' to 'unsigned long' [clang-diagnostic-sign-conversion]
   84 |         gcry_mpi_t f = gcry_mpi_set_ui(NULL, fi >= 0 ? fi : -fi);
      |                        ~~~~~~~~~~~~~~~                 ^~
tests/test_simple.c:84:61: error: operand of ? changes signedness: 'int' to 'unsigned long' [clang-diagnostic-sign-conversion]
   84 |         gcry_mpi_t f = gcry_mpi_set_ui(NULL, fi >= 0 ? fi : -fi);
      |                        ~~~~~~~~~~~~~~~                      ^~~
tests/test_simple.c:85:46: error: implicit conversion changes signedness: 'int' to 'unsigned long' [clang-diagnostic-sign-conversion]
   85 |         gcry_mpi_t p = gcry_mpi_set_ui(NULL, atoi(tests[i].p));
      |                        ~~~~~~~~~~~~~~~       ^~~~~~~~~~~~~~~~
```
Ref: https://github.com/libssh2/libssh2/actions/runs/30043871895/job/89330114459#step:24:124

Follow-up to 76d30e5 libssh2#2417
Follow-up to fcf8307 libssh2#2239
Copilot AI review requested due to automatic review settings July 23, 2026 21:12
@vszakats vszakats changed the title test_simple: cast to avoid -Wsign-conversion test_simple: cast to avoid -Wsign-conversion (clang-tidy) Jul 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the LIBSSH2_LIBGCRYPT test path in test_simple.c to silence Clang -Wsign-conversion warnings when passing int values (from atoi() and a ternary) into gcry_mpi_set_ui(), which takes an unsigned long.

Changes:

  • Add explicit casts to unsigned long for arguments passed to gcry_mpi_set_ui() in the libgcrypt test path.
  • Keep existing sign handling for negative f values via gcry_mpi_neg().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_simple.c Resolved
Copilot AI review requested due to automatic review settings July 23, 2026 21:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread tests/test_simple.c Resolved
Copilot AI review requested due to automatic review settings July 23, 2026 21:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

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.

2 participants