Euphoria
Ticket #392:
seek() crashes application when used on unopened file
-
Reported by
DerekParnell
Nov 15, 2010
The documentation on seek() states that it returns "0 on success, 1 on failure", so it should at least be returning 1 when used with an unopened file instead of crashing.
Details
1. Comment by DerekParnell
Nov 15, 2010
Currently, it also returns -1 when seeking on an opened, but unseekable, file, such as STDIN. These should be returning 1 instead of -1.
2. Comment by jimcbrown
Nov 15, 2010
Isn't this also the case for other routines such as where() and gets() and getc() ?
And for puts() and printf() and flush() and close() ?
3. Comment by DerekParnell
Nov 15, 2010
Maybe, but the docs said it returned a result. I was coding according to the docs and was surprised when my app crashed.
4. Comment by jimcbrown
Nov 15, 2010
Your fix is probably correct. The question I have is, do we now have an inconsistency in the way we handle closed files / invalid file handles? One that could confuse new users?
5. Comment by jimcbrown
Nov 15, 2010
I should restate this. Your fix is almost certainly the correct one, and the right way to do things.
6. Comment by DerekParnell
Nov 15, 2010
Those other routines do not mention how errors are handled. Some don't even return a result, eg. close().
seek() still crashes if you supply a file handle number > the max allowed number of files.
7. Comment by jimcbrown
Nov 15, 2010
Ok, good enough for me. Marking as closed...
I guess we can revisit in 5.0, when we (hopefully) can throw an exception instead of crashing the program when we get an invalid file handle.