[Top][All Lists]

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

[AUCTeX-devel] Possible infinite loop in TeX-delete-dups-by-car and TeX-

From: Ikumi Keita
Subject: [AUCTeX-devel] Possible infinite loop in TeX-delete-dups-by-car and TeX-delete-duplicate-strings
Date: Fri, 01 Sep 2017 17:21:27 +0900

Hi all,

I found that the two functions `TeX-delete-dups-by-car' and
`TeX-delete-duplicate-strings' can fall into infinite loop under certain

I'm proposing a fix, so please tell me if someone finds any problems in

[How to confirm]
1. Activate AUCTeX.
2. Evaluate (TeX-delete-duplicate-strings '("nil")) or
(TeX-delete-dups-by-car '(("nil" . 1))) .  Both examples fall into
infinite loops.

Since (string= "nil" nil) returns t, the loop
      (while (string= elt (cadr new))
        (setcdr new (cddr new)))
in `TeX-delete-duplicate-strings' never finishes when the list given as
the argument to the function ends with a string "nil" after sort.
Essentially the same reason applies for `TeX-delete-dups-by-car', too.

I estimate that it is quite uncommon that this bug causes a problem in
practical cases considering the ways that these functions are used, but
I still think it should be fixed.

[Possible fix]
The attached patch fixes the problem.  Although it may seem complicated,
the essential part is just the two occurence of
-    (while new
+    (while (cdr new)
only.  The rest are just plain rewrite using utility functions to reduce
code duplication.  (The reason that I moved the position of defun of
`TeX-car-string-lessp' is that the defcustom of `TeX-engine' requires
`TeX-delete-dups-by-car' at load time.  Thus all the functions used in
`TeX-delete-dups-by-car' must be defined before the defcustom.)

Any comments and suggestions are welcome.

Ikumi Keita

Attachment: diff
Description: fix infinite loop

reply via email to

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