summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-09-28 18:17:27 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-09-28 18:17:27 (GMT)
commite2e75c4389e2535cb9a46fd23e020aa35cce7887 (patch)
tree826a4261471c7455d8f6181142d8087ec1be5f06
parent41883cbddfa57f2b27197042f807763f31b4ecd0 (diff)
parent54252490a8ab860e77ed8e49b440755a97251b50 (diff)
downloadtcl-e2e75c4389e2535cb9a46fd23e020aa35cce7887.zip
tcl-e2e75c4389e2535cb9a46fd23e020aa35cce7887.tar.gz
tcl-e2e75c4389e2535cb9a46fd23e020aa35cce7887.tar.bz2
Fix [0df5906dd7]: Error-handling when stderr is in "strict" profile
-rw-r--r--generic/tclEvent.c32
-rw-r--r--generic/tclMain.c33
2 files changed, 46 insertions, 19 deletions
diff --git a/generic/tclEvent.c b/generic/tclEvent.c
index 541e708..0cf0df1 100644
--- a/generic/tclEvent.c
+++ b/generic/tclEvent.c
@@ -97,6 +97,8 @@ static int inExit = 0;
static int subsystemsInitialized = 0;
+static const char ENCODING_ERROR[] = "\n\t(encoding error in stderr)";
+
/*
* This variable contains the application wide exit handler. It will be called
* by Tcl_Exit instead of the C-runtime exit if this variable is set to a
@@ -294,9 +296,13 @@ HandleBgErrors(
Tcl_WriteChars(errChannel,
"error in background error handler:\n", -1);
if (valuePtr) {
- Tcl_WriteObj(errChannel, valuePtr);
+ if (Tcl_WriteObj(errChannel, valuePtr) < 0) {
+ Tcl_WriteChars(errChannel, ENCODING_ERROR, -1);
+ }
} else {
- Tcl_WriteObj(errChannel, Tcl_GetObjResult(interp));
+ if (Tcl_WriteObj(errChannel, Tcl_GetObjResult(interp)) < 0) {
+ Tcl_WriteChars(errChannel, ENCODING_ERROR, -1);
+ }
}
Tcl_WriteChars(errChannel, "\n", 1);
Tcl_Flush(errChannel);
@@ -483,18 +489,22 @@ TclDefaultBgErrorHandlerObjCmd(
if (Tcl_FindCommand(interp, "bgerror", NULL,
TCL_GLOBAL_ONLY) == NULL) {
Tcl_RestoreInterpState(interp, saved);
- Tcl_WriteObj(errChannel, Tcl_GetVar2Ex(interp,
- "errorInfo", NULL, TCL_GLOBAL_ONLY));
+ if (Tcl_WriteObj(errChannel, Tcl_GetVar2Ex(interp,
+ "errorInfo", NULL, TCL_GLOBAL_ONLY)) < 0) {
+ Tcl_WriteChars(errChannel, ENCODING_ERROR, -1);
+ }
Tcl_WriteChars(errChannel, "\n", -1);
} else {
Tcl_DiscardInterpState(saved);
- Tcl_WriteChars(errChannel,
- "bgerror failed to handle background error.\n", -1);
- Tcl_WriteChars(errChannel, " Original error: ", -1);
- Tcl_WriteObj(errChannel, tempObjv[1]);
- Tcl_WriteChars(errChannel, "\n", -1);
- Tcl_WriteChars(errChannel, " Error in bgerror: ", -1);
- Tcl_WriteObj(errChannel, resultPtr);
+ Tcl_WriteChars(errChannel, "bgerror failed to handle"
+ " background error.\n Original error: ", -1);
+ if (Tcl_WriteObj(errChannel, tempObjv[1]) < 0) {
+ Tcl_WriteChars(errChannel, ENCODING_ERROR, -1);
+ }
+ Tcl_WriteChars(errChannel, "\n Error in bgerror: ", -1);
+ if (Tcl_WriteObj(errChannel, resultPtr) < 0) {
+ Tcl_WriteChars(errChannel, ENCODING_ERROR, -1);
+ }
Tcl_WriteChars(errChannel, "\n", -1);
}
Tcl_DecrRefCount(resultPtr);
diff --git a/generic/tclMain.c b/generic/tclMain.c
index 628deaa..906c197 100644
--- a/generic/tclMain.c
+++ b/generic/tclMain.c
@@ -29,6 +29,7 @@
*/
static const char DEFAULT_PRIMARY_PROMPT[] = "% ";
+static const char ENCODING_ERROR[] = "\n\t(encoding error in stderr)";
/*
* This file can be compiled on Windows in UNICODE mode, as well as on all
@@ -249,7 +250,9 @@ Tcl_SourceRCFile(
if (Tcl_EvalFile(interp, fullName) != TCL_OK) {
chan = Tcl_GetStdChannel(TCL_STDERR);
if (chan) {
- Tcl_WriteObj(chan, Tcl_GetObjResult(interp));
+ if (Tcl_WriteObj(chan, Tcl_GetObjResult(interp)) < 0) {
+ Tcl_WriteChars(chan, ENCODING_ERROR, -1);
+ }
Tcl_WriteChars(chan, "\n", 1);
}
}
@@ -375,7 +378,9 @@ Tcl_MainEx(
if (chan) {
Tcl_WriteChars(chan,
"application-specific initialization failed: ", -1);
- Tcl_WriteObj(chan, Tcl_GetObjResult(interp));
+ if (Tcl_WriteObj(chan, Tcl_GetObjResult(interp)) < 0) {
+ Tcl_WriteChars(chan, ENCODING_ERROR, -1);
+ }
Tcl_WriteChars(chan, "\n", 1);
}
}
@@ -415,7 +420,9 @@ Tcl_MainEx(
Tcl_DecrRefCount(keyPtr);
if (valuePtr) {
- Tcl_WriteObj(chan, valuePtr);
+ if (Tcl_WriteObj(chan, valuePtr) < 0) {
+ Tcl_WriteChars(chan, ENCODING_ERROR, -1);
+ }
}
Tcl_WriteChars(chan, "\n", 1);
Tcl_DecrRefCount(options);
@@ -528,7 +535,9 @@ Tcl_MainEx(
if (code != TCL_OK) {
chan = Tcl_GetStdChannel(TCL_STDERR);
if (chan) {
- Tcl_WriteObj(chan, Tcl_GetObjResult(interp));
+ if (Tcl_WriteObj(chan, Tcl_GetObjResult(interp)) < 0) {
+ Tcl_WriteChars(chan, ENCODING_ERROR, -1);
+ }
Tcl_WriteChars(chan, "\n", 1);
}
} else if (is.tty) {
@@ -537,7 +546,9 @@ Tcl_MainEx(
(void)Tcl_GetStringFromObj(resultPtr, &length);
chan = Tcl_GetStdChannel(TCL_STDOUT);
if ((length > 0) && chan) {
- Tcl_WriteObj(chan, resultPtr);
+ if (Tcl_WriteObj(chan, resultPtr) < 0) {
+ Tcl_WriteChars(chan, ENCODING_ERROR, -1);
+ }
Tcl_WriteChars(chan, "\n", 1);
}
Tcl_DecrRefCount(resultPtr);
@@ -802,7 +813,9 @@ StdinProc(
chan = Tcl_GetStdChannel(TCL_STDERR);
if (chan != NULL) {
- Tcl_WriteObj(chan, Tcl_GetObjResult(interp));
+ if (Tcl_WriteObj(chan, Tcl_GetObjResult(interp)) < 0) {
+ Tcl_WriteChars(chan, ENCODING_ERROR, -1);
+ }
Tcl_WriteChars(chan, "\n", 1);
}
} else if (isPtr->tty) {
@@ -812,7 +825,9 @@ StdinProc(
Tcl_IncrRefCount(resultPtr);
(void)Tcl_GetStringFromObj(resultPtr, &length);
if ((length > 0) && (chan != NULL)) {
- Tcl_WriteObj(chan, resultPtr);
+ if (Tcl_WriteObj(chan, resultPtr) < 0) {
+ Tcl_WriteChars(chan, ENCODING_ERROR, -1);
+ }
Tcl_WriteChars(chan, "\n", 1);
}
Tcl_DecrRefCount(resultPtr);
@@ -883,7 +898,9 @@ Prompt(
"\n (script that generates prompt)");
chan = Tcl_GetStdChannel(TCL_STDERR);
if (chan != NULL) {
- Tcl_WriteObj(chan, Tcl_GetObjResult(interp));
+ if (Tcl_WriteObj(chan, Tcl_GetObjResult(interp)) < 0) {
+ Tcl_WriteChars(chan, ENCODING_ERROR, -1);
+ }
Tcl_WriteChars(chan, "\n", 1);
}
goto defaultPrompt;