nano-devel
[Top][All Lists]
Advanced

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

Re: [Nano-devel] solving a history bug in nano [patch]


From: Tito
Subject: Re: [Nano-devel] solving a history bug in nano [patch]
Date: Wed, 1 Jun 2016 21:23:48 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.8.0



On 06/01/2016 07:37 PM, Benno Schulenberg wrote:

On Wed, Jun 1, 2016, at 15:09, Tito wrote:
Running ./a.out here produces:

Four...  1
Much...  1
Sizet... 1

   ./test
Four...  1
Much...  1
Sizet... 0
Minus... 0

Oh.  It seems to treat a length of -1 like if it were 0.
To verify that, please compile and run this:

#include <string.h>
#include <stdio.h>

int main()
{
         printf("Equal...     %x\n", strncmp("sam", "sam", (size_t)-1));
         printf("Longer...    %x\n", strncmp("same", "sa", (size_t)-1));
         printf("Shorter...   %x\n", strncmp("sa", "same", (size_t)-1));
         printf("Similar...   %x\n", strncmp("same", "so", (size_t)-1));
         printf("Related...   %x\n", strncmp("so", "same", (size_t)-1));
         printf("Different... %x\n", strncmp("same", "po", (size_t)-1));
         printf("Other...     %x\n", strncmp("po", "same", (size_t)-1));
}

Here it produces:

Equal...     0
Longer...    1
Shorter...   ffffffff
Similar...   ffffffff
Related...   1
Different... 1
Other...     ffffffff



Hi, here:
./test2
Equal...     0
Longer...    0
Shorter...   0
Similar...   0
Related...   0
Different... 0
Other...     0

When in the call of find_history I replace '(size_t)-1' with '0', I can't
start nano at all; it aborts immediately.  Only when giving the option
--ignore does it start up.  But then I get the same behavior as alpha:

^W  aa  <Enter>
^W  bb  <Enter>
Segmentation fault


Finally, looking at the code, I get it: when -1 treats *all* strings
as being equal, it also sees the given string as equal to "", the
empty string at the end of the history.  It deletes that item, and
then, on the second search it tries to assign the new search string
to that item.  Or something similar -- it is confusing.

If, in update_history(), you change the line after the line that
says (size_t)-1, from

     if (p != NULL) {

to

     if (p != NULL && p->data[0] != '\0') {

then your nano should not segfault any more.  (You do not
build up any history either, but this is just to confirm
that my understanding is correct.)

Yes, works with no search history.

To solve it, we'll use the suggestion from alpha: pass to
find_history() the largest possible number that doesn't
have the high bit set.

Thanks for hanging in there, Tito, to get this to the right
solution.

No problem, was a pleasure.

Benno


Ciao,
Tito



reply via email to

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