On Mar 9, 3:23 pm, Eric Sosman <Eric.Sos...@sun.comwrote:
>
What is `null' and where is it defined -- or have
you posted a paraphrase instead of the actual code?
Sorry, I've been programming in java alot lately. I meant NULL, and
I'm not suspicious of the validation of the src pointer.
But if `null' is really `NULL' and <string.hhas
been #included, I can only guess that `src' points to
someplace bogus
...
Just guessing, I'm afraid ...
Actually, I appreciate your guesses! I draw the same conclusion -
somehow src must be bad.
Unfortunatley I can't see a problem through inspection. The caller
uses new to allocate an array of char for src. The caller then fills
src with data from a stream, and null terminates src. All of these
operations seem to be properly validated and range checked. I cannot
see any way that memory for src was delete'd or that src was
intentionally reassigned before the call to myfunction. So...
If the value of the src pointer does not change between caller's new
operation and my strncpy, is it possible that the caller could have
successfully used src without causing a core dump there?
If the answer to that is 'no' (and I think it is), I think that means
src was good while the caller was using it, but was unintentionally
changed after that, but before the call to strncpy, such as by a
memory trampling bug or some such. This is the only explanation I can
come up with.
Ahem - I forgot to mention that the problem is intermittent. :) To
give more context, the caller is reading records from a stream, and
myfunction needs to copy one of the strings in the record. Many
records will get processed before the core dump. I have no control
over the code that writes or reads these records, or how src is
initialized or used before it gets to myfunction. But strncpy is
where the core dump happens, so I get to debug. :)
I guess my purpose for posting is to confirm that the only thing that
can go wrong here is the caller gives myfunction a bad pointer (i.e.
myfunction is written correctly and the contents of src don't matter).