[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: alert.c
From: |
Rory Toma |
Subject: |
RE: alert.c |
Date: |
18 Oct 2002 15:31:37 -0700 |
I figured we were OK. I'm running RATS and tracking down the large
amount of (mostly harmless) warnings.
On Fri, 2002-10-18 at 15:01, Jan-Henrik Haukeland wrote:
> > In this snippet of code from alert.c:
> > *
> > I have a few questions. Why are we using a fixed sized buffer for buf?
>
> Since I'm to blame for the code I can try and answer this. The buffer is not
> fixed, I relay on a feature in gcc that allows for dynamically declaring a
> buffer size. The size is different for each string to replace. If this feature
> didn't exist or another compiler than gcc was used it would probably be better
> to malloc the string.
>
> > Wouldn't it be easier and better to malloc it?
>
> The idea (not a big point in this case) is that malloc is more expensive than
> automatic variables. Besides it's one less free() to remember.
>
> > Shouldn't we be using strncat?
>
> Since we now the size of the strings we are operating on it's okay.
>
> > Why do we free(*src) and then use it right after?
>
> Because src is the old string and buf the new replaced string, we free(() src
> to avoid a memory leak before we set src to point to the new string.
>
> I hope that explained the function?
>
> Jan-Henrik
>
>
>
> _______________________________________________
> monit-dev mailing list
> address@hidden
> http://mail.nongnu.org/mailman/listinfo/monit-dev
>
--
Rory Toma address@hidden
VP of Run Level 5 http://www.trs80.net
Digeo Digital http://www.digeo.com
signature.asc
Description: This is a digitally signed message part