Thread (28 messages) 28 messages, 2 authors, 2016-06-15

Re: [PATCH v2 01/10] sequencer.c: remove broken support for rfc2822 continuation in footer

flat view

From: Brandon Casey <hidden>
Date: 2016-06-15 22:55:51

On Tue, Jan 22, 2013 at 1:49 AM, Jonathan Nieder [off-list ref] wrote:
Jonathan Nieder wrote:
quoted
Here is the loop in master:

      int hit = 0;
[...]

      for (i = len - 1; i > 0; i--) {
              if (hit && buf[i] == '\n')
                      break;
              hit = (buf[i] == '\n');
      }

I don't see any adjacency check.
Of course that's because I can't read. :)  Checking again.
Blame the code, not your eyes.  The use of the term 'hit' is what
makes this loop confusing.  It gives the impression that 'hit' gets
set once, after the first newline is /hit/.

It would be much easier to read if it was written like this:

   int last_char_was_nl = 0;
   for (i = len - 1; i > 0; i--) {
           this_char_is_nl = (buf[i] == '\n');
           if (last_char_was_nl && this_char_is_nl)
                   break;
           last_char_was_nl = this_char_is_nl;
   }

I'll slide this in when I resubmit this series with your suggestions.

-Brandon
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help