summaryrefslogtreecommitdiffstats
path: root/generic/tclBinary.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclBinary.c')
-rw-r--r--generic/tclBinary.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/generic/tclBinary.c b/generic/tclBinary.c
index 923b536..ca9bb68 100644
--- a/generic/tclBinary.c
+++ b/generic/tclBinary.c
@@ -2594,7 +2594,8 @@ BinaryDecodeHex(
Tcl_Obj *resultObj = NULL;
unsigned char *data, *datastart, *dataend;
unsigned char *begin, *cursor, c;
- int i, index, value, size, count = 0, cut = 0, strict = 0;
+ int i, index, value, size, pure = 1, count = 0, cut = 0, strict = 0;
+ Tcl_UniChar ch = 0;
enum {OPT_STRICT };
static const char *const optStrings[] = { "-strict", NULL };
@@ -2615,8 +2616,12 @@ BinaryDecodeHex(
}
TclNewObj(resultObj);
- datastart = data = (unsigned char *)
- TclGetStringFromObj(objv[objc - 1], &count);
+ data = TclGetBytesFromObj(NULL, objv[objc - 1], &count);
+ if (data == NULL) {
+ pure = 0;
+ data = (unsigned char *) TclGetStringFromObj(objv[objc - 1], &count);
+ }
+ datastart = data;
dataend = data + count;
size = (count + 1) / 2;
begin = cursor = Tcl_SetByteArrayLength(resultObj, size);
@@ -2661,10 +2666,15 @@ BinaryDecodeHex(
return TCL_OK;
badChar:
+ if (pure) {
+ ch = c;
+ } else {
+ TclUtfToUniChar((const char *)(data - 1), &ch);
+ }
TclDecrRefCount(resultObj);
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"invalid hexadecimal digit \"%c\" at position %d",
- c, (int) (data - datastart - 1)));
+ ch, (int) (data - datastart - 1)));
Tcl_SetErrorCode(interp, "TCL", "BINARY", "DECODE", "INVALID", NULL);
return TCL_ERROR;
}