I have an older ncurses based program that performs a few simple I / O operations in multiple files (i.e.: installer). However, from a terminal other than PuTTY, it crashes with SIGBUS
Program received signal SIGBUS, Bus error. 0x00000000004028b1 in fDisplay (ptr=Variable "ptr" is not available. ) at file_cpy.c:676 676 sprintf(p, " %-36s ", (*ptr)->datainfo.option); (gdb) where
This happens on Linux and FreeBSD, regardless of the ncurses version and 32/64-bit architecture. I am completely at a dead end.
fDisplay () is called here:
int fredraw (CELL * c) { register int row = c->srow; dlistptr p = c->list_start; int i = 0; char buff[200]; if (c->ecol - c->scol) sprintf(buff, "%*s",c->ecol - c->scol + 1, " "); while (i <= c->erow - c->srow && p != NULL) { if (p == c->current) wattron(c->window,A_REVERSE); mvaddstr (row , c->scol, fDisplay(&p)); if (p == c->current) wattroff(c->window,A_REVERSE); row++; i++; p = p->nextlistptr; } if (row <= c -> erow) for (; row <= c -> erow ; row++) mvaddstr(row, c->scol, buff); wrefresh(c->window); c -> redraw = FALSE; return TRUE; }
This calls fredraw ():
int main_dir(CELL *c) { int i; getcwd(current_path, sizeof(current_path)); strcat(current_path, "/.config.h"); load_file(current_path); c->keytable = file_cpy_menu; c->func_table = file_cpy_table; c->ListEntryProc = File_Entry; c->UpdateStatusProc = status_update; c->redraw = TRUE; c->ListExitProc = List_Exit; c->ListPaintProc = fredraw; c->srow = 3; c->scol = 1; c->erow = c->window->_maxy - 5; c->ecol = c->window->_maxx - 1; c->max_rows = c->window->_maxy; c->max_cols = c->window->_maxx; c->filename = "[ Config ]"; c->menu_bar = 0; c->normcolor = 0x07; c->barcolor = 0x1f; init_dlist(c); for (i = 0; config_type[i].option; i++) insert_fdlist(c, &config_type[i]); do { c->redraw = TRUE; ls_dispatch(c); } while (c->termkey != ESC && c->termkey != ALT_X); return TRUE; }
Finally, main () calls the above functions:
int main() { CELL file_cpy = {0}; WINDOW *mainwin; mainwin = initscr(); start_color(); setup_colors(); cbreak(); noecho(); keypad(mainwin, TRUE); meta(mainwin, TRUE); raw(); leaveok(mainwin, TRUE); wbkgd(mainwin, COLOR_PAIR(COLOR_MAIN)); wattron(mainwin, COLOR_PAIR(COLOR_MAIN)); werase(mainwin); refresh(); file_cpy.window = mainwin; main_dir(&file_cpy); wbkgd(mainwin, A_NORMAL); werase(mainwin); echo(); nocbreak(); noraw(); refresh(); endwin(); return TRUE; }