[zeromq-dev] [PATCH] prefix tree bug

Martin Sustrik sustrik at 250bpm.com
Mon Aug 30 07:22:09 CEST 2010


Jon,

Yes. Thanks! I haven't accounted for the corner case where a node in the 
trie has 256 subnodes.

Mato, what's the process for committing fixes that are to be eventually 
backported to the stable?

Martin

> Prior to this patch prefix_tree asserted for me with this test program
>
> #include <prefix_tree.hpp>
> #include <iostream>
> #include <stdio.h>
>
> int main()
> {
>
> zmq::prefix_tree_t m;
>
> for (int i = 0; i < 512; i++)
> {
> printf("%08x\n",i);
> m.add((unsigned char*)&i,sizeof(int));
>
> }
> int count = 0;
> for (int i = 0; i < 512; i++)
> {
> printf("%08x\n",i);
> count += m.check((unsigned char*)&i,sizeof(int));
> }
> printf("%d\n",count);
> }
>
> this is because as it adds the 255th element at a node it attempts to
> calculate the count member var which is an unsigned char via
> count = (255 -0) + 1;
> and pass the result to realloc. Unfortunately the result is zero and
> realloc returns null;
> the prefix_tree asserts.
>
> I have fixed it by making the count an unsigned short.
>
> The fix works for me and the program above returns 512 as expected and
> valgrind doesnt gripe either, but there may be a better way.
>
> I'm submitting it under the MIT/X11 license should it be deemed acceptable.
>
> Jon
>
>
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev




More information about the zeromq-dev mailing list