Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-3972

bson-oid.h conversion warning

    • Type: Icon: Improvement Improvement
    • Resolution: Gone away
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: 1.17.3
    • Component/s: libbson
    • None
    • Environment:
      Ubuntu 20.04(GCC 9.3)

      #include <bson/bson.h>
      int main()
      {
       return 0;
      }
      

      compile with option -pipe -Wall -pedantic -Wextra -Wconversion -Wformat=1 -Wno-unused-parameter

      In file included from /usr/local/include/libbson-1.0/bson/bson-types.h:30,
                       from /usr/local/include/libbson-1.0/bson/bson-context.h:25,
                       from /usr/local/include/libbson-1.0/bson/bson.h:31,
                       from Documents/code/test_cmake/main.cpp:1:
      /usr/local/include/libbson-1.0/bson/bson-endian.h: In function ‘uint16_t __bson_uint16_swap_slow(uint16_t)’:
      /usr/local/include/libbson-1.0/bson/bson-endian.h:136:31: warning: conversion from ‘int’ to ‘uint16_t’ {aka ‘short unsigned int’} may change value [-Wconversion]
        136 |    return ((v & 0x00FF) << 8) | ((v & 0xFF00) >> 8);
            |           ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
      In file included from /usr/local/include/libbson-1.0/bson/bson.h:40,
                       from Documents/code/test_cmake/main.cpp:1:
      /usr/local/include/libbson-1.0/bson/bson-oid.h: In function ‘void bson_oid_init_from_string_unsafe(bson_oid_t*, const char*)’:
      /usr/local/include/libbson-1.0/bson/bson-oid.h:217:68: warning: conversion from ‘int’ to ‘uint8_t’ {aka ‘unsigned char’} may change value [-Wconversion]
        217 |       oid->bytes[i] = ((bson_oid_parse_hex_char (str[2 * i]) << 4) |
            |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        218 |                        (bson_oid_parse_hex_char (str[2 * i + 1])));
            |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
      

            Assignee:
            ezra.chung@mongodb.com Ezra Chung
            Reporter:
            940477049@qq.com x changnet
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: