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

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

Open
phaag opened this issue Oct 14, 2023 · 0 comments

Comments

@phaag
Copy link

phaag commented Oct 14, 2023

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.

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

No branches or pull requests

2 participants
@phaag and others