[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: time returns -1



Dale Scheetz writes:

>Yes, I guess that does qualify as technical info. I saw it as a 
>description of the function.

Um, I'd say that a description of the function was in itself technical
information, in fact.

>Well, Richard, my code looks a little different, but I think the net 
>result is the same:

No - it has an important difference.

>function()
>	{
>	time_t *jt;
>	time_t jtime;
>	
>	jtime = time(jt);

At the time of this call, jt is uninitialised.  It could be pointing
anywhere - outside your program, for example.  The kernel spots this
and (quite correctly) generates an error.  This should probably be
documented, but you shouldn't expect sane behaviour to result from
playing aroud with uninitialized pointers.

Automatic variables in C are *not* initialised to 0, 0.0, NULL or
whatever, they are not initialised to anything at all - whatever data
happens to be in that bit of memory just stays there.

>if I put the line:
>
>jt = malloc(sizeof(time_t));
>
>just before the call to time I get:
>
>jtime = 854563279

Yes, jt then points to some part of memory that is writable and so
everything just works.

>Memory says that my first code worked fine in R5 also. Can someone
>check this out on an R6 machine?

Doesn't seem very likely to me.  It's the kernel that is doing the
check.

>If this is a bug, how do I report it?

Read /usr/doc/bug-reporting.txt

-- 
Richard Kettlewell  richard@uk.geeks.org  http://www.elmail.co.uk/staff/richard/


Reply to: