[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
multiple calls of newterm can return the same SCREEN *
From: |
Mike Gran |
Subject: |
multiple calls of newterm can return the same SCREEN * |
Date: |
Tue, 24 May 2016 03:51:30 +0000 (UTC) |
Hello.
I was checking out the multiple screen functionality
ncurses when writing a unit test, and I'm not sure that
it works as described in the docs.
Granted, I'd be very unlikely to use multiple screens
outside of unit testing, but, anyway...
In the example below, I've created screens from two different
files, but the return from newterm() is the same for both.
On my box, the output is
version: ncurses 6.0.20160116
screen #1: 0x00602470 stdscr #1: 0x0066ca10
screen #2: 0x00602470 stdscr #2: 0x0066ca10
---
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ncursesw/curses.h>
int main()
{
FILE *fp1 = fopen("screen1.dat", "w+");
FILE *fp2 = fopen("screen2.dat", "w+");
SCREEN *screen1 = newterm ("vt100", fp1, fp1);
SCREEN *screen2 = newterm ("xterm", fp2, fp2);
WINDOW *stdscr1, *stdscr2;
set_term(screen1);
stdscr1 = stdscr;
addstr("hello #1");
refresh();
endwin();
set_term(screen2);
stdscr2 = stdscr;
addstr("hello #2");
refresh();
// endwin(); <-- crashes here
printf("version: %s\n", curses_version());
printf("screen #1: 0x%08x stdscr #1: 0x%08x\n", screen1, stdscr1);
printf("screen #2: 0x%08x stdscr #2: 0x%08x\n", screen2, stdscr2);
delscreen(screen2);
// delscreen(screen1); <-- double free here
fclose (fp2);
fclose (fp1);
return 0;
}
- multiple calls of newterm can return the same SCREEN *,
Mike Gran <=