[comp.os.minix] fixes to unshar.c and ast.c

XBR4D75G%DDATHD21.BITNET@cunyvm.cuny.edu (03/20/90)

During my upgrade process to 1.5.5, I found the following bugs in the
official version of programs "unshar.c" and "ast.c".

"unshar.c" contained a simple spelling error, two characters must be
interchanged.

*** unshar.old  Tue Mar 20 13:50:00 1990
--- unshar.c    Tue Mar 20 13:51:06 1990
***************
*** 104,110 ****
            case '\"':
            case '\'':
                buf++;
!               inquotes != inquotes;   /* Toggle inquotes */
                break;
            case 0:
            case '\n':          /* Stop on <, >, NULL */
--- 104,110 ----
            case '\"':
            case '\'':
                buf++;
!               inquotes = !inquotes;   /* Toggle inquotes */
                break;
            case 0:
            case '\n':          /* Stop on <, >, NULL */

The problem with program "ast.c" is more serious, because I only have a method
to circumvent the error but not to correct the real problem.

During execution of "ast" the o_file is opened by two different routines
( fopen() and open() ) and the file-descriptors are position to different
places:

  if ((o_fd = fopen(o_file, "a")) == (FILE *) NULL) {
          .........
  }
  fseek(o_fd, A_SYMPOS(header), SEEK_SET);
           ........
    if ((fd = open(o_file, O_RDONLY)) < 0) {
             ........
    }
    if (read(fd, &header, sizeof(struct exec)) != sizeof(struct exec)) {
             .........
    }
             .........
    close(fd);
             .........
  if (fwrite(symbol, sizeof(struct nlist), 1, fd) != 1) {
             .........
  }
             .........
  fclose(o_fd);

The official version 1.5.5 of "ast" writes the symbol-table at the beginning
of o_file instead to append it. Here is a possible fix to this:

*** ast.old     Tue Mar 20 12:08:22 1990
--- ast.c       Tue Mar 20 13:40:52 1990
***************
*** 83,89 ****
        fprintf(stderr, "can't open %s\n", o_file);
        exit(-1);
    }
-   fseek(o_fd, A_SYMPOS(header), SEEK_SET);
    if (s_file == (char *) NULL) s_file = SYMBOL_FILE;
    if ((s_fd = fopen(s_file, "r")) == (FILE *) NULL) {
        fprintf(stderr, "can't open %s\n", s_file);
--- 83,88 ----
***************
*** 91,96 ****
--- 90,96 ----
    }
    nr_symbols = 0;
    do_header();
+   fseek(o_fd, A_SYMPOS(header), SEEK_SET);
    ast();
    fclose(o_fd);
    redo_header();

Hans-Juergen Knobloch, (T.H. Darmstadt, West Germany)

nfs@notecnirp.Princeton.EDU (Norbert Schlenker) (03/22/90)

In article <14467@nigel.udel.EDU> XBR4D75G%DDATHD21.BITNET@cunyvm.cuny.edu writes:
>During my upgrade process to 1.5.5, I found the following bugs in the
>official version of programs "unshar.c" and "ast.c".
>[unshar fix deleted]
>The problem with program "ast.c" is more serious, because I only have a method
>to circumvent the error but not to correct the real problem.
>[ast fix deleted]

Actually, this is a pretty good fix.  When I posted this version of
ast, I neglected to test it with the old stdio code (which I have
dumped in favour of my own, and which I don't keep on disk anymore ...
I have no space).  So this is all my fault.  The code worked for me,
and I bet it works for anyone using Earl Chew's stdio package too.

The old stdio's fopen() doesn't really support ANSI semantics,
although it would be fairly easy to change now that 1.5 supports the
O_APPEND flag in open().  I think that the stdio package should be
dumped before 1.5 is finalized, and either Earl's or my package
adopted as the standard.

Failing such a change, I'll volunteer to fix fopen(), freopen(), and
fdopen() so that they'll work correctly with 1.5 and the old stdio, IF
(there's always an IF) someone will send me copies that match the
1.5.5 CRC list.

Norbert