summaryrefslogtreecommitdiffstats
path: root/generic/tclEncoding.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-07-19 14:23:31 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-07-19 14:23:31 (GMT)
commit515bd7c0e7439f19f59c33be1ff8089de8f4417f (patch)
treeb026ec4941b3da0d496a0d541dc3c8ff6e4afb24 /generic/tclEncoding.c
parent50eeabb1014676f4bcc1fe38a06a5d3ef8806044 (diff)
downloadtcl-515bd7c0e7439f19f59c33be1ff8089de8f4417f.zip
tcl-515bd7c0e7439f19f59c33be1ff8089de8f4417f.tar.gz
tcl-515bd7c0e7439f19f59c33be1ff8089de8f4417f.tar.bz2
Improve error-reporting possibilities for Tcl_ExternalToUtfDStringEx/Tcl_UtfToExternalDStringEx in case no interpreter is available, by setting "errno".
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r--generic/tclEncoding.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index deaabaa..83510cc 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -1290,6 +1290,7 @@ Tcl_ExternalToUtfDStringEx(
"Parameter error: TCL_ENCODING_{START,STOP} bits set in flags.",
TCL_INDEX_NONE));
Tcl_SetErrorCode(interp, "TCL", "ENCODING", "ILLEGALFLAGS", NULL);
+ errno = EINVAL;
return TCL_ERROR;
}
@@ -1333,17 +1334,20 @@ Tcl_ExternalToUtfDStringEx(
/* Caller wants error message on failure */
if (result != TCL_OK && interp != NULL) {
char buf[TCL_INTEGER_SPACE];
- snprintf(buf, sizeof(buf), "%u", nBytesProcessed);
+ snprintf(buf, sizeof(buf), "%" TCL_SIZE_MODIFIER "u", nBytesProcessed);
Tcl_SetObjResult(
interp,
Tcl_ObjPrintf("unexpected byte sequence starting at index %"
- "u: '\\x%02X'",
+ TCL_SIZE_MODIFIER "u: '\\x%02X'",
nBytesProcessed,
UCHAR(srcStart[nBytesProcessed])));
Tcl_SetErrorCode(
interp, "TCL", "ENCODING", "ILLEGALSEQUENCE", buf, NULL);
}
}
+ if (result != TCL_OK) {
+ errno = (result == TCL_CONVERT_NOSPACE) ? ENOMEM : EILSEQ;
+ }
return result;
}
@@ -1527,7 +1531,7 @@ Tcl_UtfToExternalDString(
* The parameter flags controls the behavior, if any of the bytes in
* the source buffer are invalid or cannot be represented in the
* target encoding. It should be composed by OR-ing the following:
- * - *At most one* of TCL_ENCODING_PROFILE{DEFAULT,TCL8,STRICT}
+ * - *At most one* of TCL_ENCODING_PROFILE_*
* - TCL_ENCODING_STOPONERROR: Backward compatibility. Sets the profile
* to TCL_ENCODING_PROFILE_STRICT overriding any specified profile flags
*
@@ -1590,6 +1594,7 @@ Tcl_UtfToExternalDStringEx(
"Parameter error: TCL_ENCODING_{START,STOP} bits set in flags.",
TCL_INDEX_NONE));
Tcl_SetErrorCode(interp, "TCL", "ENCODING", "ILLEGALFLAGS", NULL);
+ errno = EINVAL;
return TCL_ERROR;
}
@@ -1630,21 +1635,25 @@ Tcl_UtfToExternalDStringEx(
} else {
/* Caller wants error message on failure */
if (result != TCL_OK && interp != NULL) {
- int pos = Tcl_NumUtfChars(srcStart, nBytesProcessed);
+ Tcl_Size pos = Tcl_NumUtfChars(srcStart, nBytesProcessed);
int ucs4;
char buf[TCL_INTEGER_SPACE];
TclUtfToUCS4(&srcStart[nBytesProcessed], &ucs4);
- snprintf(buf, sizeof(buf), "%u", nBytesProcessed);
+ snprintf(buf, sizeof(buf), "%" TCL_SIZE_MODIFIER "u", nBytesProcessed);
Tcl_SetObjResult(
interp,
Tcl_ObjPrintf(
- "unexpected character at index %d: 'U+%06X'",
+ "unexpected character at index %" TCL_SIZE_MODIFIER
+ "u: 'U+%06X'",
pos,
ucs4));
Tcl_SetErrorCode(interp, "TCL", "ENCODING", "ILLEGALSEQUENCE",
buf, NULL);
}
}
+ if (result != TCL_OK) {
+ errno = (result == TCL_CONVERT_NOSPACE) ? ENOMEM : EILSEQ;
+ }
return result;
}