[ntp:hackers] Segfaults in ntp-dev

David L. Mills mills at udel.edu
Sun Jun 3 13:33:55 PDT 2007


Guys,

The ntp-dev version has two known segfaults, maybe more. The fudge ... 
time1 command segfaults in line 310 of ntp_config.c, but I can't find 
anything wrong by looking at variables and pointers. I have a suspicion 
though, and I'd like to ask for expert opinion.

A number of routines in Sachin's code declare a structure and return a 
pointer to it. Obviously, the compiler can't put this on the stack, as 
would ordinarily be the case. I would assume the compiler recognizes 
this case in context and puts the structure on the heap. This makes me 
nervous.

When I taught programming languages in a previous life, dumb compilers 
insisted local declarations be on the stack, so Sachin's style was 
forbidden. My preferred style is to declare a local pointer, malloc the 
structure (on the heap), set the local pointer to the structure and 
return the local pointer. Machines of the day returned values in the AC 
and MQ 36-bit registers and had only three index registers.

My question is, am I a wuss or a wise man?

Dave


More information about the hackers mailing list