Error-handling in TclGetOpenMode()
$ tclsh8.6
% open README.md {RDWR RDONLY}
file3
This should be invalid, as `RDWR` and `RDONLY` are incompatible. Also, it doesn't handle repeating:
$ tclsh8.6
% open README.md {RDWR RDWR}
file3
This was noted while working on TIP #691, but since it would make the TIP implementation unneccesary big it's better to separate it.
9d86f86f41Merge [22e66b7f413a16ea]: Fix [e155cedf33]: Error-handling in TclGetOpenMode(). check-in2024-08-27 11:23:5022e66b7f41Fix [e155cedf33]: Error-handling in TclGetOpenMode() check-in2024-04-11 08:35:5168ff52f3c7Fix [e155cedf33]: Error-handling in TclGetOpenMode(). Add O_ACCMODE fow Windows, in case it is not defined check-in2024-04-11 07:57:231de2bb21a5[e155cedf33]: Error-handling in TclGetOpenMode() check-in2024-04-10 13:18:37
Great, Jan, great action.
I saw your commit: https://core.tcl-lang.org/tcl/info/1de2bb21a5da29a2 -> great action
The unmodified line 1182 of file generic/tclIOCmd.c states:
default:
Tcl_Panic("Tcl_OpenCmd: invalid mode value");
break;
}
I suppose, this is from old times and should be transfered to an assertion or a real error return. Shall I care?
Take care, Harald
> I suppose, this is from old times ...
In this case, "mode" is produced by the function TclGetOpenModeEx(), and it can only be O_RDONLY, O_WRONLY or O_RDWR. It's impossible to produce another value through user input. Therefore, I think we can keep this Tcl_Panic(): it's impossible to trigger this at script level (neither at C-API level).
Thanks for the explanation - great !
Fixed [here], present now in core-8-branch and trunk.
It's not really necessary to backport this to 8.6