- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Dateline : 2025/11/26.
There are no comments on this article yet (there will be in a moment), which might be because the actual dateline on the article is 2025/12/02, and yet the Random Article button let me see it anyway...
Admin
did you submit it to last week Error'd?
Edit Admin
Unfortunately, I didn't think of doing that at the time, then I forgot about it in the meantime, until I saw it come up today.
Edit Admin
Ooohhh, that would have been WAY too much fun!
I need to get out more....
Edit Admin
I'm going to go out on a limb and assume ExtractFileName isn't a pure function either, which would make debugging all the more painful.
Edit Admin
It seems a fairly minor WTF but the whole
is itself a WTF since there is a race condition in that, if it exists, something else might have deleted it before you get to do what you want to do with it. You might as well just go ahead and do the operation without testing for existence and handle the errors if they arise.
Edit Admin
ExtractFileName is a pure function. It returns the argument without the drive and directory.
Edit Admin
Yeah, what I tend to call a "toctou" == "Time of Check, Time of Use" (name derived from the reports from the static analyser we use at $JOB).
Edit Admin
Back in Ye Olden Dayes of computers running one app at a time and no multi-threading, TOCTOU (an industry standard term) wasn't nearly the code smell it is today. Given that we're talking about Delphi, decent bet this is a nearly single-threaded application where the only thing that could disturb that file between check and use is a hard drive failure. Or maybe somebody opening the floppy drive door at just the right moment. ;)
Also back in Ye Olden Dayes the way you checked for errors in most languages was itself pretty laborious, code intensive, and bug-prone. From a code cleanliness perspective they're probably better off the way they are.
Addendum 2025-12-02 10:28: Would I recommend writing TOCTOU bugs in a modern multi-threaded multi-user app written in a modern exception-driven language?
Of course not.
Admin
Hello from the future!
Edit Admin
And yet people still do it. TOCTOU is what took down US-EAST-1 AWS a little while ago.