[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Two bugs (and fixes) in ncurses-5.2

From: Tom Riddle
Subject: Two bugs (and fixes) in ncurses-5.2
Date: Tue, 09 Jan 2001 18:40:24 -0500


I believe I have found two bugs in ncurses-5.2-20001021.

Both bugs exhibit themselves only under the following conditions:
- no terminfo database
- no TERMCAP env var
- termcap entry requires merging

1. The first bug is a result of the fact that the entries of the Strings 
array in TERMTYPE are simply copied while merging in _nc_merge_entry():

     * Note: the copies of strings this makes don't have their own
     * storage.  This is OK right now, but will be a problem if we
     * we ever want to deallocate entries.
    for_each_string(i, from) {
        char *mergestring = from->Strings[i];

        if (mergestring == CANCELLED_STRING)
            to->Strings[i] = ABSENT_STRING;
        else if (mergestring != ABSENT_STRING)
            to->Strings[i] = mergestring;

So that after a merge the Strings entries may be pointing to the 
str_table of another TERMTYPE.  This becomes a problem when the 
other TERMTYPEs are freed in _nc_free_entries().

The solution that I came up with is to add a new routine called 
_nc_fixup_merged_entry() that gets called after merging.  What it 
does is to copy all the things that occupy space in str_table
(which, AFAICT, is term_names, Strings and uses) to stringbuf, then
(conceptually) calls _nc_wrap_entry().  I say conceptually because 
wrap_entry also gives ext_str_table the same treatment, which we 
don't want to do here, so I wound up copying most of wrap_entry 
in place.  I did it this way to localize my changes, it would 
obviously be better to refactor this and have both wrap_entry
and fixup_merged_entry call another routine.

2. The second bug occurs in postprocess_termcap() where key_backspace,
key_left, key_down are overwritten:

    if (!hard_copy) {
        if (WANTED(key_backspace))
            key_backspace = _nc_save_str(C_BS);
        if (WANTED(key_left))
            key_left = _nc_save_str(C_BS);
        if (WANTED(key_down))
            key_down = _nc_save_str(C_LF);

The problem is that this takes place before any merging is done, so 
that if these are not defined in the current entry, but are defined in 
a reference one, the referenced one will never get copied.  My solution 
is to make the above code predicated on has_base:

    if (!has_base) {

Similar to much of the other code in this routine.

Attached is a patch that corrects both of these issues.  I can supply
that demonstrates these problems, if need be, but I have to go now -
I have a life beyond this :-)

I am not subscribed to the list, so please respond to me directly.



Tom Riddle

Oracom, Inc.

Tel. +1 978.557.5710x305
Fax  +1 978.557.5716

Attachment: ncurses.patch
Description: Binary data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]