[comp.os.minix] BUG in 1.5.10 commands/file.c

droege@infko.UUCP (Detlev Droege G 207) (08/09/90)

Hi folks,

there is a small but nasty bug in commands/file.c which causes it
to dump core on empty files. The case of zero length files is not
tested for and thus drives the type-guessing for-loop mad ...

The fix is easy, see patch below. And it makes it conformant to the
behaviour of the file commands I'm used to on BSD and SysV.

	Bye
		Detlev

---------------- cut here for best results ----------------
*** file.c.orig Thu Aug  9 15:15:42 1990
--- file.c      Thu Aug  9 15:15:35 1990
***************
*** 81,86 ****
--- 81,91 ----
	close(fd);
	return;
    }
+   if (n == 0) {       /* must check this, for loop will fail otherwise !! */
+       printf("empty file\n");
+       close(fd);
+       return;
+   }
  
    /* Check to see if file is an archive. */
  #if (CHIP == M68000)
-----------------------------------------------------------
--
Detlev Droege, Uni Koblenz (EWH), FB Informatik
	       Rheinau 3-4, D-5400 Koblenz   (Germany)
UUCP: ..!unido!infko!droege   droege@infko.UUCP   (Voice: +49 261 9119-421)