Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

TCSH crashes only when in a TCC console

May
12,834
163
Since a UNIX-like shell was mentioned in another thread, I thought I'd see how TCSH was working (after a long time). I'll make a long story short. TCSH's built-in "title" command (set the console title) crashes TCSH like this (ONLY if TCSH was started by TCC).
Code:
v:/> title foo
title: No match.
free(0x7fbd7748) bad block. (memtop = 0x7fc0f000 membot = 0x7fbb0000)
 
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
(along with a message box: "tcsh.exe has stopped working)

This does not happen if TCSH was started by a stand-alone CMD, by a stand-alone PowerShell, or by a CMD started by TCC. The story is odd for TCSH started by a PowerShell started by TCC. If I had not manually set PowerShell's title ($Host.UI.RawUI.WindowTitle = "some title") then TCSH will crash as above. If I had manually set PS's title, TCSH's "title" command works OK.

I can't imagine why being in a TCC console would make a difference. FWIW, here's TCSH's "dotitle" code.
Code:
void dotitle(Char **vc, struct command * c) {
 
    int k;
    char titlebuf[512];
    char errbuf[128],err2[128];
    char **v;
 
    UNREFERENCED_PARAMETER(c);
    vc++;
    vc = glob_all_or_error(vc);
    cleanup_push(vc, blk_cleanup);
 
    if ((k=GetConsoleTitle(titlebuf,512) ) != 0) {
        titlebuf[k]=0;
        setcopy(STRoldtitle,str2short(titlebuf),VAR_READWRITE);
    }
 
    memset(titlebuf,0,512);
    v = short2blk(vc);
    cleanup_until(vc);
    cleanup_push((Char **)v, blk_cleanup);
    for (k = 0; v[k] != NULL ; k++){
        __try {
            StringCbCat(titlebuf,sizeof(titlebuf),v[k]);
            StringCbCat(titlebuf,sizeof(titlebuf)," ");
        }
        __except(GetExceptionCode()) {
            stderror(ERR_TOOMANY);
        }
    }
 
    if (!SetConsoleTitle(titlebuf) ) {
        make_err_str(GetLastError(),errbuf,128);
        (void)StringCbPrintf(err2,sizeof(err2),"%s",v[k]);
        stderror(ERR_SYSTEM,err2,errbuf);
    }
    cleanup_until((Char **)v);
    return;
}
void docls(Char **vc, struct command *c) {
    UNREFERENCED_PARAMETER(vc);
    UNREFERENCED_PARAMETER(c);
    NT_ClearScreen_WholeBuffer();
}
 
I found where TCSH's "title" command is crashing, in the "setcopy" function below (not in "str2short").
Code:
    if ((k=GetConsoleTitle(titlebuf,512) ) != 0) {
        titlebuf[k]=0;
        setcopy(STRoldtitle,str2short(titlebuf),VAR_READWRITE);
    }

That's entirely CRT stuff (TCSH setting the shell variable "oldtitle"). There appears to be some very, very strange CRT anomaly that's vaguely related to TITLEPROMPT.

TCSH's "title" command does not crash if I start TCSH like this
Code:
title foo & g:\tcmd\tcsh.exe
And TCSH does not misbehave if I start it from a TCC where TITLEPROMPT is not set. So it would seem to be the case that something in the RTL prevents TCSH's "title" command from working correctly if the last TCC title was set via the TITLEPROMPT mechanism. It's very strange, but I have tested it thoroughly. I remember a couple years ago when TCMD's crashing at shutdown was mysteriously related to the TITLEPROMPT mechanism.
 
Never mind. It is entirely TCSH's problem. My TITLEPROMPT contains "[%_PID]" and when saving the old title, TCSH crashes when trying to de-reference (not sure why) the bracketed string inside. I reported the issue. Actually I had reported the crash 4 years ago but at that time I didn't know what caused it.
 

Similar threads

Back
Top