> Date: Tue, 16 Aug 2022 09:54:25 -0700 > Cc: bug-gnulib@gnu.org, la...@gnus.org, 57...@debbugs.gnu.org, > jporterb...@gmail.com, Bruno Haible <br...@clisp.org> > From: Paul Eggert <egg...@cs.ucla.edu> > > On 8/16/22 09:25, Eli Zaretskii wrote: > > The programmer didn't > > expect that because it is natural to expect each call to a function > > that creates a temporary file to create a file under a new name, not > > reuse the same name. > > Regardless of whether the programmer expects a random name or a > predictable-but-unique name, there are only a finite number of names to > choose from so the programmer must take into account the possibility > that the chosen name clashes with names that the programmer would prefer > not to be chosen.
Then what is this comment and the following assertion in Bruno's code about? /* With 6 'X' and a good pseudo-random number generator behind the scenes, the probability of getting the same file name twice in a row should be 1/62^6 < 1/10^10. */ ASSERT (strcmp (filename1, filename2) != 0); That "finite number" of 62^6 sounds pretty close to infinity to me! > This means an Emacs patch such as [1] is needed regardless of whether > Gnulib's gen_tempname is changed to be more random than it is. Although > it's true that the bug fixed by [1] is less likely if gen_tempname > generates more-random names, the bug can occur no matter what we do > about gen_tempname. No, sorry. I object to this patch, because it hides the problem under the carpet. That there's a file-visiting buffer that records the name of a temporary file is just one case where this issue gets in the way. The general problem is still there. And it isn't an Emacs problem, so Emacs is not the place to solve it. Therefore, if there's no intention to fix this in Gnulib, I'm going to update the documentation of make-temp-file so that Emacs users and programmers will be informed about that and will be careful enough to side-step these issues in all the situations. (Not that I understand why won't Gnulib provide consistent behavior on all platforms, but I guess it's above my pay grade.)