Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Error-handling in TclGetOpenMode()

Closed / Fixede155cedf33aca13baf5ab0f3749b00861d8924d5Created 3 years agoUpdated 3 years ago
Descriptionwiki2024-04-10 13:16:58
Function TclGetOpenMode() doesn't do much error-handling. For example:
$ 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.

Referenced by4
oehharwiki2024-04-10 14:31:24

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

jan.nijtmanswiki2024-04-10 14:42:23

> 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).

oehharwiki2024-04-10 16:28:36

Thanks for the explanation - great !

jan.nijtmanswiki2024-04-11 08:39:32

Fixed [here], present now in core-8-branch and trunk.

It's not really necessary to backport this to 8.6

Log in (anonymous is fine) to add a comment.