[Bro-Dev] min() and max() problem in util.h
gregor at icir.org
Wed Nov 24 07:38:33 PST 2010
when fixing a 32 bit overflow in the HTTP analyzer, I cam across a
problem with the min() and max() function defined (as inline) in util.h
Their signature is int min (int,int), which fails for 64bit values and
which will also fails for comparing uints.
One could write a bunch of overloaded min/max function to handle all
kinds of argument types correctly. However, I don't like overloading
with too many too similar parameter types (bad experience with hard to
One way to solve this, would be to explicitly name the min/max functions
according to their type, e.g.,
min_i32(), min_u32(), min_u64(), min_64()....
Or, I can just replace the min/max function with a macro. However, then
the problem is, that the expression that's passed to min/max will be
evaluated twice, which is a problem if it has side effects.....
Gregor Maier gregor at icir.org
Int. Computer Science Institute (ICSI) gregor at icsi.berkeley.edu
1947 Center St., Ste. 600 http://www.icir.org/gregor/
Berkeley, CA 94704
More information about the bro-dev