--- tclIO.c.orig	Fri Nov  9 10:30:45 2007
+++ tclIO.c	Fri Nov  9 10:50:07 2007
@@ -7056,14 +7056,26 @@
 	if (argc == 0) {
 	    statePtr->inEofChar = 0;
 	    statePtr->outEofChar = 0;
-	} else if (argc == 1) {
-	    if (statePtr->flags & TCL_WRITABLE) {
-		statePtr->outEofChar = (int) argv[0][0];
+	} else if (argc == 1 || argc == 2) {
+	    int outIndex = (argc - 1);
+	    int inValue = (int) argv[0][0];
+	    int outValue = (int) argv[outIndex][0];
+	    if ((inValue < 0x01 || inValue > 0x7f) || (outValue < 0x01 || outValue > 0x7f)) {
+		if (interp) {
+		    Tcl_AppendResult(interp,
+			    "bad value for -eofchar: must be between 0x01 and 0x7f",
+			    NULL);
+		}
+		ckfree((char *) argv);
+		return TCL_ERROR;
 	    }
 	    if (statePtr->flags & TCL_READABLE) {
-		statePtr->inEofChar = (int) argv[0][0];
+		statePtr->inEofChar = inValue;
 	    }
-	} else if (argc != 2) {
+	    if (statePtr->flags & TCL_WRITABLE) {
+		statePtr->outEofChar = outValue;
+	    }
+	} else {
 	    if (interp) {
 		Tcl_AppendResult(interp,
 			"bad value for -eofchar: should be a list of zero,"
@@ -7071,13 +7083,6 @@
 	    }
 	    ckfree((char *) argv);
 	    return TCL_ERROR;
-	} else {
-	    if (statePtr->flags & TCL_READABLE) {
-		statePtr->inEofChar = (int) argv[0][0];
-	    }
-	    if (statePtr->flags & TCL_WRITABLE) {
-		statePtr->outEofChar = (int) argv[1][0];
-	    }
 	}
 	if (argv != NULL) {
 	    ckfree((char *) argv);
