htags generates incorrect anchor when -s option is specified.

Shuichi KITAGUCHI <[email protected]>
Newsgroups gmane.comp.gnu.global.bugs
Message-ID <[email protected]>
Hi,

I've found that htags command generates incorrect anchor link when -s
option is specified on FreeBSD and Cygwin. Linux is ok.  Upon
investigation, this seems to be caused by behaviour of qsort().

When anchor->lineno is same and cmp()@htags/anchor.c returns 0, some
qsort() impelmentation might swap objects. This causes that type 'R'
is upper than type 'T', and anchor_get() cannot find correct anchor.

If appling below patch to htags/anchor.c, htags seems generate correct
link.

 static int
 cmp(const void *s1, const void *s2)
 {
+#if 1
+	int diff = ((struct anchor *)s1)->lineno - ((struct anchor *)s2)->lineno;
+	/* when lineno is same, preserve current order. */
+	return diff == 0 ? -1 : diff;
+#else
 	return ((struct anchor *)s1)->lineno - ((struct anchor *)s2)->lineno;
+#endif
 }
 /*
  * Pointers (as lineno).

Is this right fix?

Thanks,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.