Hi everybody, this is my first post here.
I'm trying to find out why lib_ncurses' initscr() is failing on me, so I compiled a quick program that runs it and attached gdb to it. I've only used gdb a few times, so I think I might be misinterpreting what I'm seeing, but this doesn't make any sense to me.
I isolated the problem to a pointer that is pointing nowhere. In the code below, typeCalloc(TERMINAL, 1) is just a macro that equates to (TERMINAL *)typeCalloc(1, sizeof(TERMINAL)).
(gdb) list 549,554
549 termp = typeCalloc(TERMINAL, 1);
550
551 if (termp == 0) {
552 ret_error0(TGETENT_ERR,
553 "Not enough memory to create terminal structure.\n");
554 }
555 #if USE_DATABASE || USE_TERMCAP
556 status = grab_entry(tname, &termp->type);
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/mslade/sandbox/c/crawler/notes/curses
Breakpoint 4, _nc_setupterm (tname=0xbfd24bb7 "xterm", Filedes=1, errret=0xbfd23668, reuse=false) at ../ncurses/./tinfo/lib_setup.c:549
549 termp = typeCalloc(TERMINAL, 1);
(gdb) print termp
$8 = (TERMINAL *) 0x0
(gdb) step
551 if (termp == 0) {
(gdb)
549 termp = typeCalloc(TERMINAL, 1);
(gdb)
551 if (termp == 0) {
(gdb)
549 termp = typeCalloc(TERMINAL, 1);
(gdb)
360 int status = _nc_read_entry(tn, filename, tp);
(gdb)
Can anyone help me understand why it would hit line 549 three times, and never hit line 552? At the end, it jumps to 360, which is inside grab_entry().
When I run the program, I never see that "Not enough memory ..." error message, which is what I would expect it malloc were failing. Instead, it's continuing on to the rest of the function.
Thanks,
Mark