Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-9985

Compilation Ubuntu 20.04 (ARM64) - Implicit conversion changes signedness

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • WT11.2.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • 3
    • StorEng - Defined Pipeline

      Reproducer:
      Spawn a host using ubuntu2004-arm64-large (-small should work too).

      Execute the following steps from a WiredTiger repo:

      . test/evergreen/find_cmake.sh 
      mkdir cmake_build && cd cmake_build
      $CMAKE -DCMAKE_BUILD_TYPE=ASan -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/mongodbtoolchain_v4_clang.cmake -DHAVE_BUILTIN_EXTENSION_LZ4=1 -DHAVE_BUILTIN_EXTENSION_SNAPPY=1 -DHAVE_BUILTIN_EXTENSION_ZLIB=1 -DHAVE_BUILTIN_EXTENSION_ZSTD=1 -G Ninja ../.
      ninja
      

      You should observe the following error messages:

      ../ext/encryptors/rotn/rotn_encrypt.c:153:51: error: implicit conversion changes signedness: 'int' to 'char' [-Werror,-Wsign-conversion]
                  buf[i] = ((buf[i] - 'a') + rotn) % 26 + 'a';
                         ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
      ../ext/encryptors/rotn/rotn_encrypt.c:155:51: error: implicit conversion changes signedness: 'int' to 'char' [-Werror,-Wsign-conversion]
                  buf[i] = ((buf[i] - 'A') + rotn) % 26 + 'A';
      

      This fixes the compilation warnings but I have not done any testing:

      diff --git a/examples/c/ex_encrypt.c b/examples/c/ex_encrypt.c
      index ce94394..f8657b3 100644
      --- a/examples/c/ex_encrypt.c
      +++ b/examples/c/ex_encrypt.c
      @@ -110,9 +110,9 @@ do_rotate(char *buf, size_t len, int rotn)
           for (i = 0; i < len; i++)
               if (isalpha((unsigned char)buf[i])) {
                   if (islower((unsigned char)buf[i]))
      -                buf[i] = ((buf[i] - 'a') + rotn) % 26 + 'a';
      +                buf[i] = (char)(((buf[i] - 'a') + rotn) % 26 + 'a');
                   else
      -                buf[i] = ((buf[i] - 'A') + rotn) % 26 + 'A';
      +                buf[i] = (char)(((buf[i] - 'A') + rotn) % 26 + 'A');
               }
       }
       
      diff --git a/ext/encryptors/rotn/rotn_encrypt.c b/ext/encryptors/rotn/rotn_encrypt.c
      index ccf87c6..6b05a12 100644
      --- a/ext/encryptors/rotn/rotn_encrypt.c
      +++ b/ext/encryptors/rotn/rotn_encrypt.c
      @@ -150,9 +150,9 @@ do_rotate(char *buf, size_t len, int rotn)
            */
           for (i = 0; i < len; i++) {
               if ('a' <= buf[i] && buf[i] <= 'z')
      -            buf[i] = ((buf[i] - 'a') + rotn) % 26 + 'a';
      +            buf[i] = (char)(((buf[i] - 'a') + rotn) % 26 + 'a');
               else if ('A' <= buf[i] && buf[i] <= 'Z')
      -            buf[i] = ((buf[i] - 'A') + rotn) % 26 + 'A';
      +            buf[i] = (char)(((buf[i] - 'A') + rotn) % 26 + 'A');
           }
       }
      

            Assignee:
            sona.reddy@mongodb.com Sona Reddy (Inactive)
            Reporter:
            etienne.petrel@mongodb.com Etienne Petrel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: