From 8d662734b6a34709d9475b120e7ce3de872339e2 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 4 Sep 2022 11:44:01 -0700 Subject: [PATCH] Revert "gvc auto_output_filename: avoid 'strdup' when constructing file name" This reverts commit 4291cc769a3eeef8b1c171e5479194733a4da6cd. This commit that was intended to be a functional no-op actually altered the generated output filename to remove `.` characters. Github: xflr6/graphviz #178, NixOS/nixpkgs #188175 Gitlab: fixes #2270 Reported-by: Sebastian Bank --- CHANGELOG.md | 2 ++ lib/gvc/gvdevice.c | 26 ++++++++------------------ tests/test_regression.py | 1 - 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ab3b3dfd..218a2f913 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 ### Fixed - Id attribute is not used in linearGradient. #2258 +- Graphviz 5.0.1 undocumented change of automatically generated output filename + with -O flag (missing dot separator). This was a regression in 5.0.1. #2270 ### Removed diff --git a/lib/gvc/gvdevice.c b/lib/gvc/gvdevice.c index aca908f11..dfe68871d 100644 --- a/lib/gvc/gvdevice.c +++ b/lib/gvc/gvdevice.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -87,7 +86,7 @@ static void auto_output_filename(GVJ_t *job) static char *buf; static size_t bufsz; char gidx[100]; /* large enough for '.' plus any integer */ - char *fn; + char *fn, *p, *q; size_t len; if (job->graph_index) @@ -108,23 +107,14 @@ static void auto_output_filename(GVJ_t *job) strcpy(buf, fn); strcat(buf, gidx); strcat(buf, "."); - - { - char *dst = buf + strlen(buf); - const char *src = job->output_langname; - const char *src_end = src + strlen(src); - for (const char *q = src_end; ; --q) { - if (*q == ':') { - sprintf(dst, "%.*s.", (int)(src_end - q - 1), q + 1); - dst += (size_t)(src_end - q - 1); - src_end = q; - } - if (q == src) { - sprintf(dst, "%.*s", (int)(src_end - src), src); - break; - } - } + p = strdup(job->output_langname); + while ((q = strrchr(p, ':'))) { + strcat(buf, q+1); + strcat(buf, "."); + *q = '\0'; } + strcat(buf, p); + free(p); job->output_filename = buf; } diff --git a/tests/test_regression.py b/tests/test_regression.py index e3fcf5944..6316adf24 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -1952,7 +1952,6 @@ def test_2258(): for gradient in gradients: assert "G2" in gradient.get("id"), "ID was not applied to linear gradients" -@pytest.mark.xfail(strict=True) def test_2270(tmp_path: Path): """ `-O` should result in the expected output filename -- 2.40.0