klib icon indicating copy to clipboard operation
klib copied to clipboard

implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1

Open phaag opened this issue 8 months ago • 0 comments

Obviously some compiles interpret a 1bit int32_t as negativ.

warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
KBTREE_INIT(ifTree, nameNode_t, nodeCMP)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/kbtree.h:378:2: note: expanded from macro 'KBTREE_INIT'
        __KB_PUT(name, key_t, __cmp)                            \
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/kbtree.h:215:32: note: expanded from macro '__KB_PUT'
                        b->root = s; s->is_internal = 1; s->n = 0;                                      \
                                                    ^ ~

Patch: Change the type of kbnode in kbtree.h to unsigned int.

typedef struct {
    uint32_t is_internal : 1, n : 31;
} kbnode_t;

This should have no impact.

phaag avatar Oct 14 '23 14:10 phaag