lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lynx-dev disappearing empty lines (was: THANKS AND QUESTION)


From: Klaus Weide
Subject: Re: lynx-dev disappearing empty lines (was: THANKS AND QUESTION)
Date: Tue, 4 Jan 2000 06:45:48 -0600 (CST)

Actually, looking at print_wwwfile_to_fd in dev.17, the following
logic for suppressing newlines is wrong:

    for (;; line = line->next) {
        if (!first &&
         line->data[0] != LY_SOFT_NEWLINE &&
         line->data[0] != '\0' &&
         line->data[1] != LY_SOFT_NEWLINE) {
            /* data[0] can be LY_*START_CHAR, so LY_SOFT_NEWLINE can be in [1] 
- VH */
            fputc('\n',fp);

This will quite obviously give the wrong behavior (non-execution of
hte fputc) in the case of line->data[0] == '\0' (a completely empty
line, no special chars either).

The line->data[0] != '\0' condition was added by J. Bley, to guard
against accessing line->data[1] which may be invalid memory if the
line size is 0.  The unguarded access to line->data[1] was added
a bit earlier by VH (see comment).  VH didn't check JB's modification
of his code.

A corrected logic for the condition would be

        if (!first &&
         line->data[0] != LY_SOFT_NEWLINE &&
         !(line->data[0] != '\0' &&
           line->data[1] == LY_SOFT_NEWLINE)) {

which is the same as

        if (!first &&
         line->data[0] != LY_SOFT_NEWLINE &&
         (line->data[0] == '\0' ||
          line->data[1] != LY_SOFT_NEWLINE)) {

or

        if (!first &&
          (line->data[0] == '\0' ||
           (line->data[0] != LY_SOFT_NEWLINE &&
            line->data[1] != LY_SOFT_NEWLINE))) {

Actually, to match more closely the motivation from the comment, replace
line->data[0] != '\0' with IsSpecialAttrChar(line->data[0]).

The following function, print_crawl_to_fd, has the same original problem
of potential invalid access to line->data[1], yet has not suffered through
a wrong correction attempt.

  ---

While corrections are obvious, I still find the logic behind VH's change
questionable:

            /* data[0] can be LY_*START_CHAR, so LY_SOFT_NEWLINE can be in [1] 
- VH */

Why and since when?  Has this always been a problem (if yes, why was
it not found earlier?), or only been introduced by, say, -prettysrc
source mode?  Or one of the other new modes with which VH has blessed
us more recently?

If data[0], can be LY_*START_CHAR, then so can presumably data[1], and
possibly more.   Without knowing that that can never actually happen,
the added test looks like a partial ad hoc fix up, not a real solution.

IMO the code that adds LY_SOFT_NEWLINE to a line should make sure that
it gets put at the beginning of a line, maybe by re-ordering before
LY_*START_CHARs if necessary, so that no fixups are necessary in other
code that later has to process the lines.

Vlad, please send patches.


   Klaus


reply via email to

[Prev in Thread] Current Thread [Next in Thread]