Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

heap_insert unsafe #1563

Open
scunningham opened this issue Nov 7, 2014 · 1 comment
Open

heap_insert unsafe #1563

scunningham opened this issue Nov 7, 2014 · 1 comment

Comments

@scunningham
Copy link

Although understandably an edge case, heap_insert should fail to insert a new node if heap->nelts == UINT_MAX.

It is possible, though unlikely, that unsigned int is 16 bit. Even in a 32 bit world, hitting UINT_MAX becomes more likely as machines get faster.

At the very least it should assert(heap->nelts < UINT_MAX). It would be better to abort() than blindly corrupt the data structure.

@bnoordhuis
Copy link
Contributor

It is possible, though unlikely, that unsigned int is 16 bit.

Libuv does not claim to support platforms where ints have fewer than 32 bits. (What does, these days?)

Even in a 32 bit world, hitting UINT_MAX becomes more likely as machines get faster.

I don't think that's realistic on 32 bit architectures: in order to hit UINT_MAX, you need to insert 2^32 elements - but that requires more memory than a 32 bits architecture can address.

It could become an issue on 64 bits architectures however. I see two solutions: adding that assert you suggest or changing the type of nelts to uintptr_t.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants