Buggy bro sort() function

Hi all:

The attached brogram demonstrates that the bro sort() function does not sort correctly under certain circumstances (tested on OS/X & Linux). The behavior also occurs when using the common function idiom of sort(myvec, function(a: int, b: int): int { return a-b;});

I haven’t examined bro source code, but since some of the test values are larger than 32 bits, I surmise that there is a casting from 64 to 32 bits that could change the sign of the comparison, thus causing this problem.

Mitigation is to use a function that returns the sign of subtraction results, rather than the actual subtraction results, something like sort(myvec, function(a: int, b: int): int { return a<b ? -1 : (a>b ? 1 : 0);});


Jim Mellander

badsort.bro (539 Bytes)

Turns out that a number of other BIFs are not 64-bit safe, rand(), order(), to_int() are examples.

Filing a bug report.