oswordreadclock_utc

David J. Ruck druck at freeuk.com
Sat Jul 7 22:07:08 BST 2001


Hi,

I've been plagued by an obscure bug in the developemnt version of DiscKnight
for a month now, its been hell of a job tracking it down, as it occurred in
random addresses in the SharedCLibrary, left no stack back trace, only
occurred with certain datasets, and didn't occur when built with memory
checking or debug data.

I finally tracked it down to a small function that called oswordreadclock_utc
that was on certain occations overwriting the stack frame and causing
problems later in the program when strlen was called. 

My usuage of oswordreadclock_utc was as follows:-

void MakeLoadExec(bits *loadaddr, bits *execaddr)
{
    oswordreadclock_utc_block utc;
    oswordreadclock_utc(&utc);
    *loadaddr = 0xFFF00000 | (osfile_TYPE_DATA<<8) | utc.utc[4];
    *execaddr = *(bits*)utc.utc;
}

On disassembling this function and oswordreadclock_utc it turns out that it
is not setting up the reason code in the oswordreadclock_utc_block block
before making the call to OS_Word. This caused a random value to be used,
which if 0 to 2 would cause more space after the 5 byte allocated on the
stack frame to be corrupted - this bug must have been in all previous
versions of the program, but did not cause problems until this version
when I split code into the seperate MakeLoadExec function so it could be
used from more than one location.

My question is, should oswordreadclock_utc and its related functions
xoswordreadclock_local_string, xoswordreadclock_local_bcd,
xoswordreadclock_convert_bcd_to_string and the equivelent write clock
functions set up the reason code in the block themselves? 

I assumed that as each is an individual named function to perform the
specific operation, that with no documentation in headers or StrongHelp
manuals to say their entry conditions required the block to be initialised,
the reason code would be inserted by the function. Does anyone else agree?
Are there any other similar functions where this does or does not occur?

Cheers
---Dave

-- 
____________________________________________________________________________

  David J. Ruck    Phone: +44- (0)7974 108301    Email: druck at freeuk.com
____________________________________________________________________________



More information about the oslib-user mailing list