Skip to content

Segfault caused by cpptcl interfering with USE_TCL_STUBS #10

Open
@mutability

Description

@mutability

This program crashes with a segfault; it tries to call Tcl_CreateInterp via the tcl stubs pointer, but the stubs pointer is null. (case 1)

#include "cpptcl.h"
#include "tcl.h"

int main(int argc, char **argv) {
  Tcl_CreateInterp();
  return 0;
}

This program does not crash (case 2)

#include "tcl.h"

int main(int argc, char **argv) {
  Tcl_CreateInterp();
  return 0;
}

This program also does not crash (case 3)

#include "tcl.h"
#include "cpptcl.h"

int main(int argc, char **argv) {
  Tcl_CreateInterp();
  return 0;
}

The cause is that cpptcl.h is defining USE_TCL_STUBS before including tcl.h
This is inappropriate for the case where cpptcl is being used from a program that's just embedding tcl, rather than an extension to be embedded in an existing interpreter.

Whether it actually breaks things is very dependent on the order of includes; if tcl.h is included before cpptcl.h, then cpptcl.h's USE_TCL_STUBS has no effect and everything is fine.

example2.cc in the cpptcl tree is an example of case 3. Swapping the order of the includes produces case 1, which then crashes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions