[tlbuild] dvi test?
John Hawkinson
jhawk at alum.mit.edu
Mon Jan 31 04:42:23 CET 2022
John Hawkinson <jhawk at alum.mit.edu> wrote on Sun, 30 Jan 2022
at 22:20:31 EST in <YfdVfxRWBAurmv2W at louder-room.local>:
> if (fstat(fileno(m_dvi_fp), &fstatbuf) != 0 || S_ISDIR(fstatbuf.st_mode)) { /* if it's a directory */
So, this code seems wrong.
fstat(2) returns 0 on success, and -1 on failure. Normally we test its return value against -1.
So here, if fstat(2) succeeds, then first half of the condition (!= 0) is false, and then we try to evaluate S_ISDIR() to see if its true.
But it's not reasonable to call S_ISDIR on fstatbuf, since fstatbuf is only written to if fstat(2) had succeeded.
If fstat(2) fails, then the if condition shortcircuits (because -1 != 0), and then we set *errflag = FILE_IS_DIRECTORY, but
that's wrong because we don't know why fstat(2) failed and whether S_ISDIR() would have returned true.
That said, I don't think this is really our problem. But I applied this patch:
--- a/texk/xdvik/dvi-init.c
+++ b/texk/xdvik/dvi-init.c
@@ -1242,7 +1242,11 @@ file_exists_p(const char *path, dviErrFlagT *errflag)
/* fprintf(stderr, "after internal_open_dvi2: xfopen\n"); */
/* shouldn't happen */
- if (fstat(fileno(m_dvi_fp), &fstatbuf) != 0 || S_ISDIR(fstatbuf.st_mode)) { /* if it's a directory */
+ int rv = fstat(fileno(m_dvi_fp), &fstatbuf);
+ if (rv == -1) {
+ perror("fstat");
+ }
+ if (S_ISDIR(fstatbuf.st_mode)) { /* if it's a directory */
*errflag = FILE_IS_DIRECTORY;
fclose(m_dvi_fp);
m_dvi_fp = NULL;
which I think is correct (well, probably calling perror(3) isn't how xdvi wants to handle errors, but close enough for debuggin),
and it did not change anything. xdvi still crashes after shift-R.
That said, if insert a return True; after the fstat() call, I do see Dicks' crash prior to hitting shift-R.
So something depends on fstat() being called here, which is...weird! (As previously noted.)
--
jhawk at alum.mit.edu
John Hawkinson
More information about the tlbuild
mailing list.