Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

Not widely known problem in programming? (Developers)

posted by Laaca Homepage, Czech republic, 27.03.2021, 20:06

I would like to share my experience with source of several my very mysterious programming bugs. In several cases I for many hours tried to debug some part of my program and was not able to find the bug. Sometimes I've given to up and sometimes I've avoided the problem with some ugly hack but never really found what was wrong.
The typical symptom is that everything works just fine but it stops working after some change in program - usually in very different part of program. The term "stops working" means that the program crashes. Sometimes crashes only the program but sometimes whole DOS.
The debugger usually reports the error into some graphic procedure but it is apparently misleading.

Recently I investigated such behaviour in my editor Blocek and found the reason. I suspected some uninitialised pointer bug (known and frequent problem) but found something what was new for me.

In several pieces of my code I found that I am referencing global pointer to local stack.
The problem is that everything works OK for very long time but "sometimes" - usually in assembler graphic functions which work with such pointer the crash occurs.
Such function touches the memory where before was our data by own purposes and because of that the referenced value is overwritten and the behaviour is after that undefined.
I tried to strip the problem to be the example as simple as possible. Look at the code bellow. The bug is in the procedure "Test_Obj.Init" where I am assigning the "message" pointer into local stack.
Than the Test_Obj.Display works but there is still the permanent danger that in case of extending the program the incrimined part of memory will be overwritten and the program will crash or will not work in the right way.
Maybe you thing that I am stupid because such obvious bug can make only a idiot but trust me - if is it a real-life code (not this trivial sample) it can be very difficult to find it.

Have you ever faced to this type of bug?
Does the compilers (I am interrested mainly inf Freepascal) have some mechanism which does -something- with the local stack to demask such latent programming bug?

And the promised code example:

Program ObjTest;
type
test_obj=object
message:pchar;
procedure Init;
procedure Display;
end;

Procedure test_obj.Init;
var s:string;        {variable on local stack}
begin
s:='Hello'#0;
message:=@s[1];      {public reference to local stack}
end;

Procedure test_obj.Display;
begin
writeln(message);
end;

var to:test_object;
begin
to.Init;
to.Display;
end.

---
DOS-u-akbar!

 

Complete thread:

Back to the forum
Board view  Mix view
22049 Postings in 2034 Threads, 396 registered users, 118 users online (0 registered, 118 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum