[sword-devel] navigation arithmetic error in -r2400
Karl Kleinpaste
karl at kleinpaste.org
Mon May 11 06:46:05 MST 2009
We had this Xiphos bug report:
> Go to 1 Samuel 1; click the up button beside the chapter; Xiphos
> navigates to Judges 21 instead of Ruth 4.
Having stepped through this problem, it is a Sword bug, not a Xiphos
bug. The Xiphos code in question is this:
tmpkey = backend->get_valid_key(navbar.key->str);
vkey.AutoNormalize(1); // line 147
vkey = tmpkey;
chapter = (direction ? (vkey.Chapter()+1) : (vkey.Chapter()-1));
vkey.Chapter(chapter);
Basically, the idea is to find where we are, do arithmetic to move by 1
chapter, and tell Sword to re-navigate to that point.
When stepping through these lines, I see this behavior:
147 vkey.AutoNormalize(1);
(gdb) p tmpkey
$1 = 0xb4ffd38 "1Sam 1:1"
(gdb) n
148 vkey = tmpkey;
(gdb)
149 chapter = (direction ? (vkey.Chapter()+1) : (vkey.Chapter()-1));
(gdb)
150 vkey.Chapter(chapter);
(gdb) p chapter
$2 = 0
(gdb) p vkey
$3 = {<sword::SWKey> = {<sword::SWObject> = {myclass = 0xd44480},
...
book = 9 '\t', chapter = 1, verse = 1, suffix = 0 '\0', BMAX = {39, 27}}
(gdb) n
151 tmpkey = g_strdup_printf("%s %d:1", vkey.getBookName(), vkey.Chapter());
(gdb) p vkey
$4 = {<sword::SWKey> = {<sword::SWObject> = {myclass = 0xd44480},
...
book = 7 '\a', chapter = 21, verse = 22, suffix = 0 '\0', BMAX = {39, 27}}
(gdb) n
152 gtk_entry_set_text(GTK_ENTRY(navbar.lookup_entry), tmpkey);
(gdb) p tmpkey
$5 = 0xbdb5ec8 "Judges 21:1"
As you can see, Sword normalized so as to handle chapter 0, but instead
of going down 1 book, to Ruth, it went down 2 books, to Judges.
Very nearly identical code to handle book and verse navigation does not
have the same problem. I don't know why this would be, though an
educated guess says it might have to do with management of fictitious
verses 0:0 and n:0.
It's a minor problem, not really much of a hassle, but I thought it
ought to be mentioned. I've closed the Xiphos bug report as being a
Sword problem, but I will re-open it to address it again if someone has
a reason for why chapter navigation in this manner should be different
from book and verse navigation.
More information about the sword-devel
mailing list