From: dohm@magnus.acs.ohio-state.edu (Peter J Dohm)
Subject: minicom broken under .98-5
Summary: text segment problems, plus some...
Keywords: linux
Organization: The Ohio State University
Date: Tue, 17 Nov 1992 06:27:28 GMT

Hi all....

I have discovered that Minicom has broken in numerous ways due to the new
text segment protection.  For one, there was a line in function win_init
in window.c that had:

char *gname = "stuff"

then later:

gname[1]='x';
this seg faulted... (no kidding, right?)

it needed to be changed to something like:

char *gname;

gname=(char *)malloc(2);  (the original string was 2 bytes in length)
strcpy(gname,"whatever");  (take the original string in the declaration and
                            place it here)

that was a pretty simple problem to fix... however...
i've now got a lockup condition that I've not been able to correct.
here is the code that it's dying in:

(note that it makes it until the case statement some lines below without
a problem)

void init_emul(type)
int type;
{
  int x = -1, y = -1;
  char attr;

  if (st != NIL_WIN) {
  	wclose(st, 1);
  	tempst = 0;
  	st = NIL_WIN;
  }

  if (us != NIL_WIN) {
	x = us->curx; y = us->cury;
	attr = us->attr;
  	wclose(us, 0);
  }	
  /* Open a new window. */
  us = wopen(0, 0, 79, 23 + (type == MINIX && LINES > 24),
  			BNONE, A_NORMAL, SFG, SBG, 1);

  if (x >= 0) {
  	wlocate(us, x, y);
  	wsetattr(us, attr);
  }

  if (type == VT100)
  	wresetam(us);
  else
  	wsetam(us);
  linewrap = -1;	

  us->autocr = 0;

  /* See if we have space for a status line */
  if (LINES > (24 + (type == MINIX)) && P_STATLINE[0] == 'e')
  	st = wopen(0, 24 + (type == MINIX), 79, 24 + (type == MINIX),
  			BNONE, A_REVERSE, WHITE, BLACK, 1);

  if (type == MINIX && terminal != MINIX && LINES > 24) {
  	x = us->curx;
  	y = us->cury;
  	wlocate(us, 0, 24);
  	wclreol(us);
  	wlocate(us, x, y);
  }

  terminal = type;
  lines = 24 + ((type == MINIX) && LINES > 24);
  cols = 80;
  
  /* If "keyserv" process is stopped, it will still react to
   * some signals.
   */
  switch(type) {
  	case VT100:
  		keyserv(KVT100, 0);
  		break;
  	case MINIX:
  		keyserv(KMINIX, 0);
  		break;
  	case ANSI:
  		keyserv(KANSI, 0);
  		break;
  }



/* 
following this case statement, if i write something out to the screen,
(via a printf)
it makes it there, readable.  i usually include a sleep(1) after all my
debug statements.. so the following worked:
*/

#ifdef DEBUG
printf("ok... were're going to try and show the status bar\n");
sleep(1);
#endif




  if (st != NIL_WIN) show_status();

/*
however we've never made it to here... see below in show_status...
*/

#ifdef DEBUG
  printf("trying init vt100 - ");
  sleep(1);
#endif

  init_vt(); /* in v100.c */

#ifdef DEBUG
  printf("successful\n");
  sleep(1);
#endif
}

/*
 * Locate the cursor at the correct position in
 * the user screen.
 */
static void ret_csr()
{
  wlocate(us, us->curx, us->cury);
  wflush();
}

/*
 * Show baudrate, parity etc.
 */
void mode_status()
{
  wlocate(st, 20, 0);
  wprintf(st, " %-5s %s%s1", P_BAUDRATE, P_BITS, P_PARITY);
  ret_csr();
}

/*
 * Show offline or online time.
 * If real dcd is not supported, Online and Offline will be
 * shown in capitals.
 */
void time_status()
{
  wlocate(st, 66, 0);
  if (online < 0)
  	wputs(st, P_HASDCD[0] == 'Y' ? " Offline     " : " OFFLINE     ");
  else
  	wprintf(st," %s %02ld:%02ld", P_HASDCD[0] == 'Y' ? "Online" : "ONLINE",
  		online / 3600, (online / 60) % 60);
  		
  ret_csr();
}

/*
 * Update the online time.
 */
static void updtime()
{
  static int old_online = 0;

  if (old_online == online) return;
  old_online = online;
  if (st != NIL_WIN) {
  	time_status();
  	ret_csr();
  }
  wflush();
}

/*
 * Show the status line 
 */
void show_status()
{



/* here's where the bizzarities start to occur:
if i put the same #ifdef DEBUG statement as before, it *never* gets printed...
the only difference is that now the ip should be pointing to the beginning
of the code to print the string, and the stack should contain a new pointer
for reentry... 
I'm not sure I understand why, but it just doesn't make it into this
function correctly...
can anyone venture a guess WHY?????
the program hangs right at the beginning of this function... never returns.
gone... dead...
*/



  wlocate(st, 0, 0);
  wprintf(st, " %7.7sZ for help |           | FDX | Minicom %-9.9s |       | ",
  	esc_key(), version);
  mode_status();
  time_status();
  wlocate(st, 59, 0);
  switch(terminal) {
  	case VT100:
  		wputs(st, "VT100");
  		break;
  	case MINIX:
  		wputs(st, "MINIX");
  		break;
  	case ANSI:
  		wputs(st, "ANSI");
  		break;
  }
  ret_csr();
}


Some quick notes:

the flags I tried compiling this with was:

-O6 -s -fomit-frame-pointer

-O2 -s -fomit-frame-pointer

-O -s -fomit-frame-pointer

-O -fomit-frame-pointer

-fomit-frame-pointer

and no optimizing switches

NONE worked...

I figured it could be an gcc optimizing bug, but i don't thing it is...
(i'd love to be proven wrong, though...)

So, if anyone can figure this one out, i'd be really appreciative...
(i don't like to have to go to dos to download ;)

Pete
---
+---------------------------------------------------------------------------+
|  Peter J. Dohm - Comp. Science Major    |    The Ohio State University    |
| ** dohm@magnus.acs.ohio-state.edu **    |   ak541@cleveland.freenet.edu   |
| dohm.1@osu.edu, dohm@cis.ohio-state.edu |     dohm@cis.ohio-state.edu     |
+---------------------------------------------------------------------------+
Newsgroups: comp.os.linux