Hi,
I recently shot myself in the foot using the following BroString constructor:
> BroString::BroString(int arg_final_NUL, byte_vec str, int arg_n)
> {
> b = str;
> n = arg_n;
> final_NUL = arg_final_NUL;
> use_free_to_delete = 0;
> }
I didn't realize that when creating a new BroString, the byte_vec I pass in
doesn't get copied. I was using the byte_vec I was passing in further down, and
couldn't understand why BroString wasn't acting properly. (byte_vec is defined
as u_char*, not as a constant).
BroString::Set uses memcpy to copy the string. The other constructors all seem
to use BroString::Set.
> BroString::BroString(const u_char* str, int arg_n, int add_NUL)
> ...
> Set(str, arg_n, add_NUL);
>
> BroString::BroString(const char* str)
> ...
> Set(str);
>
> BroString::BroString(const string &str)
> ...
> Set(str);
>
The behavior is inconsistent at best. Personally, when I create a new string
object, I'd expect the data to be copied, but I could see a few special cases
where you might want to avoid that for performance reasons.
Any thoughts on this? Is this intended behavior? I suspect that any changes to
BroString would require a lot of changes downstream.
--Vlad
_______________________________________________
bro-dev mailing list
[email protected]
http://mailman.icsi.berkeley.edu/mailman/listinfo/bro-dev