From: Matthew Fernandez Date: Mon, 14 Mar 2022 05:27:02 +0000 (-0700) Subject: Revert "rewrite indexOf" X-Git-Tag: 4.0.0~169^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=51d787ece01fb4443db5eabd6932046b7b715dbc;p=graphviz Revert "rewrite indexOf" This reverts commit 84efe93d5c5a4da0e778dbf01ed8550d2d774fdf. Gitlab: fixes #2211 --- diff --git a/CHANGELOG.md b/CHANGELOG.md index f2510b3af..8dc35e90d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - spurious "no hard-coded metrics" warnings on labels with empty lines #2179 - fixed corruption of user shape characteristics during EPSF initialization - output formats canon, dot, and xdot are not completely faithful to input #2184 +- gvpr index function produces wrong results #2211. This was a regression in + Graphviz 2.47.0. ## [3.0.0] – 2022-02-26 diff --git a/lib/gvpr/actions.c b/lib/gvpr/actions.c index c2f4b4b3a..6d2713366 100644 --- a/lib/gvpr/actions.c +++ b/lib/gvpr/actions.c @@ -56,8 +56,22 @@ Agraph_t *sameG(void *p1, void *p2, char *fn, char *msg) */ int indexOf(char *s1, char *s2) { - char *s = strstr(s1, s2); - return s == NULL ? -1 : (int)(s1 - s); + char c1 = *s2; + char c; + char *p; + int len2; + + if (c1 == '\0') + return 0; + p = s1; + len2 = strlen(s2) - 1; + while ((c = *p++)) { + if (c != c1) + continue; + if (strncmp(p, s2 + 1, len2) == 0) + return ((p - s1) - 1); + } + return -1; } /* rindexOf: diff --git a/rtest/test_regression.py b/rtest/test_regression.py index 2bfca5190..27dd231dc 100644 --- a/rtest/test_regression.py +++ b/rtest/test_regression.py @@ -1563,7 +1563,6 @@ def test_2193(): assert canonical == new, "canonical translation is not stable" @pytest.mark.skipif(shutil.which("gvpr") is None, reason="GVPR not available") -@pytest.mark.xfail(strict=True) def test_2211(): """ GVPR’s `index` function should return correct results