[Oisf-devel] Source code technical question
Duarte Silva
duarte.silva at serializing.me
Tue Jul 30 14:01:25 UTC 2013
On Monday 29 July 2013 18:46:23 Victor Julien wrote:
> On 07/25/2013 11:32 AM, Duarte Silva wrote:
> > Hi all,
> >
> > in "util-host-os-info.c", functions "SCHInfoValidateIPV4Address"and
> > "SCHInfoValidateIPV6Address" are exaclty the same as "util-radix-tree.c"
> > functions "SCRadixValidateIPV4Address" and "SCRadixValidateIPV6Address".
> >
> > With a small exception in "SCHInfoValidateIPV4Address", it doesn't exit if
> > the memory allocation fails.
> >
> > Would it be a good idea to merge this functions?
>
> Definitely. Code duplication is evil. :)
>
> Are you interested in doing this?
Yes. Since this functions are IP related, should I do something to the "util-
cidr.h/c" files or leave them as they are and just add the new "util-ip.h/c"
files?
Regards,
Duarte
>
> Cheers,
> Victor
>
> > Best regards,
> > Duarte
> >
> > On Wednesday 24 July 2013 15:10:46 Duarte Silva wrote:
> >> On Wednesday 24 July 2013 15:47:19 Victor Julien wrote:
> >>> On 07/24/2013 03:21 PM, Duarte Silva wrote:
> >>>> Hi all,
> >>>>
> >>>> I was dwelling into Suricata source code and came across this:
> >>>>
> >>>> #define DEBUG_ASSERT_FLOW_LOCKED(f) do { \
> >>>>
> >>>> if ((f) != NULL) { \
> >>>>
> >>>> int r = SCMutexTrylock(&(f)->m); \
> >>>> if (r == 0) { \
> >>>>
> >>>> BUG_ON(1); \
> >>>>
> >>>> } \
> >>>>
> >>>> } \
> >>>>
> >>>> } while(0)
> >>>>
> >>>> Just wondering, whats the advantage of having this inside a do/while?
> >>>> Is
> >>>> it
> >>>> because the compiler will optimize it out if not in a debug build?
> >>>
> >>> Answers can be found on stackoverflow:
> >>>
> >>> http://stackoverflow.com/questions/923822/whats-the-use-of-do-while0-whe
> >>> n-> > we -define-a-macro
> >>> http://stackoverflow.com/questions/154136/do-while-and-if-else-statemen
> >>> ts-> > i n-c-c-macros
> >>> http://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for
> >>
> >> Thanks Victor, I should have googled it :D it never crossed my mind it
> >> had
> >> anything to do with semi-colons and code blocks. I allways use brackets
> >> even for one instruction if's. Hence, when the macro required a code
> >> block I just used brackets (it was the Microsoft compiler though, might
> >> be different from GCC).
> >>
> >> Thanks,
> >> Duarte
More information about the Oisf-devel
mailing list