From 33f1af8e7165bf137ce1be099d9a63964c409e8c Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 27 Oct 2024 20:45:10 -0400 Subject: [PATCH] Fixes for places that used Text$find() --- stdlib/paths.c | 8 +++++--- stdlib/stdlib.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/stdlib/paths.c b/stdlib/paths.c index 8acc34f..e8a1e1f 100644 --- a/stdlib/paths.c +++ b/stdlib/paths.c @@ -439,9 +439,11 @@ public Text_t Path$write_unique_bytes(Path_t path, Array_t bytes) char buf[PATH_MAX] = {}; strcpy(buf, path_str); - int64_t suffixlen = 0; - (void)Text$find(path, Pattern("{0+!X}{end}"), I(1), &suffixlen); - if (suffixlen < 0) suffixlen = 0; + // Count the number of trailing characters leading up to the last "X" + // (e.g. "foo_XXXXXX.tmp" would yield suffixlen = 4) + size_t suffixlen = 0; + while (suffixlen < len && buf[len - 1 - suffixlen] != 'X') + ++suffixlen; int fd = mkstemps(buf, suffixlen); if (fd == -1) diff --git a/stdlib/stdlib.c b/stdlib/stdlib.c index 34acc82..d90f574 100644 --- a/stdlib/stdlib.c +++ b/stdlib/stdlib.c @@ -441,7 +441,7 @@ public void end_test(const void *expr, const TypeInfo_t *type, const char *expec Text_t expr_plain = USE_COLOR ? generic_as_text(expr, false, type) : expr_text; bool success = Text$equal(&expr_plain, &expected_text); if (!success) { - Int_t colon = Text$find(expected_text, Text(":"), I_small(1), NULL); + Int_t colon = Text$find(expected_text, Text(":"), I_small(1)); if (colon.small != I_small(0).small) { Text_t with_type = Text$concat(expr_plain, Text(" : "), type_name); success = Text$equal(&with_type, &expected_text);