delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/22/12:15:57

From: Michal Mertl <xmerm05 AT manes DOT vse DOT cz>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Bug caused by ____crtl_startup+138
Date: Wed, 22 Apr 1998 18:08:25 +0200
Organization: Prague University of Economics
Lines: 51
Message-ID: <Pine.ULT.3.95.980422174530.6504B-100000@manes.vse.cz>
References: <3537BABA DOT 7D4D AT cableol DOT co DOT uk>
NNTP-Posting-Host: manes.vse.cz
Mime-Version: 1.0
In-Reply-To: <3537BABA.7D4D@cableol.co.uk>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Fri, 17 Apr 1998, Allen's wrote:
> When I run some programs, I get a crash, when symify-ied I get
> ____crtl_startup+138.  What does this do, and how can I stop it?
> 
> Source for one of the programs used to compile it:
<- snipp ->
> int col=0;
> int ma,mat,n,y=50,x=50,start,loop,div,k,go;
> char map [100][100],row[80][160],drawhat;
> 
>  
>    allegro_init();
>    install_keyboard(); 
>      set_gfx_mode(GFX_VGA, 320, 200, 0, 0); 
A good habit is to always check for results of functions which may fail.
Set_gfx_mode is definitely one of them eventhough GFX_VGA can be set probably
on every computer.
> set_pallete(desktop_pallete);
> for (loop = 0; loop < 500; loop++){
> for (start = 80; start > 0; start=start-2){
> 
> for (n = - (start-2); n < (start/2); n++)
> {
You can yourself find that values at first iteration are 
start==80,
col==0,
x==50,
y==50,
n==-78
so you are accessing places in memory out of the array bounds, this results in
unexpected behaviour of everything :)

                          !!130!! !!-28!! 
> row [start][col] = map [y+start][x+n];
              !!240!!       !!-28!! !!-30!!         
> row [start][col+240] = map [y+n][x-start];

There are some more out of arrays accesses in your code.

<- snip the rest of code ->

Hope this helps

One question: I don't know what _stklen is, but assume it changes
stack size of the executable. If so you wouldn't need to enlarge it if you
move the array definitions (or declarations ? - never know which is which)
out of main and they won't eat the stack. 

Michal "MiMe" Mertl
  xmerm05 AT vse DOT cz

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019