GNU bug report logs - #63196
sxml or guile bug?

Previous Next

Package: guile;

Reported by: Christopher Lam <christopher.lck <at> gmail.com>

Date: Mon, 1 May 2023 02:34:02 UTC

Severity: normal

Full log


Message #11 received at 63196 <at> debbugs.gnu.org (full text, mbox):

From: <tomas <at> tuxteam.de>
To: Christopher Lam <christopher.lck <at> gmail.com>
Cc: 63196 <at> debbugs.gnu.org
Subject: Re: bug#63196: Further on this error message
Date: Sat, 6 May 2023 14:38:06 +0200
[Message part 1 (text/plain, inline)]
On Mon, May 01, 2023 at 10:44:18AM +0800, Christopher Lam wrote:
> The source seems to be sxpath.scm -- see "yikes" error which triggers when
> n is -2 -4 -6 etc. I don't know how to build guile from sources and cannot
> debug further.
> 
> 
> (define (node-pos n)
>   (lambda (nodeset)
>     (cond
>      ((not (nodeset? nodeset)) '())
>      ((null? nodeset) nodeset)
>      ((eqv? n 1) (list (car nodeset)))
>      ((negative? n) ((node-pos (+ n 1 (length nodeset))) nodeset))
>      (else
>       (or (positive? n) (error "yikes!"))
>       ((node-pos (1- n)) (cdr nodeset))))))

Hm. It seems that calling `node-pos' with n == 0 runs straight into the
"yikes" case (unless `nodeset' is #f or null, that is).

And we would get this when n ==-2 and (length nodeset) equals 1 on the
next recursive call. Or when n == -3 and (length nodeset) == 2, and so
on -- i.e. when n == -1 - (length nodeset).

We reach such a point again when n == 2*(-1 - (length nodeset)): it runs
into the case (negative? n), retries with n' = (+ n 1 (length nodeset))
which is still negative, next try is 0 => yikes.

So in your case I guess your (length nodeset) is 1, because you have
a cycle length of two :-)

Reading between the lines in the code above for the positive case, I
gather that the intention is to return an empty nodeset (i.e. '())
when n runs off the nodeset. So I'd extend the ((negative? n) ...)
case like so:

  ((negative? n)
    (let ((nn (+ 1 (length nodeset))))
      (if (positive? nn) (node-pos nn) '())))

Comments?

Cheers
-- 
t
[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 2 years and 41 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.