Posted to tcl by thommey at Tue Jul 19 17:36:56 GMT 2011view raw
- #include <stdio.h>
- #include <stdlib.h>
- #include <tcl.h>
- int main(int argc, char **argv) {
- int flags, size;
- char *dst, *src = "#test\\\\\\";
- Tcl_Interp *interp;
- Tcl_FindExecutable(argv[0]);
- interp = Tcl_CreateInterp();
- if (Tcl_Init(interp) != TCL_OK) {
- fprintf(stderr, "Failure to initialize: %s\n", Tcl_GetStringResult(interp));
- return 1;
- }
- size = Tcl_ScanElement(src, &flags);
- dst = malloc(size+1);
- printf("%d\n", flags); // crash happens when flags==4 (CONVERT_ESCAPE)
- printf("%d\n", Tcl_ConvertElement(src, dst, flags)); // SEGFAULT (dereferencing NULL pointer)
- printf("'%s' - '%s'\n", src, dst);
- free(dst);
- return 0;
- }