From d91a4133b0ad6bb5f53fdbd9ae0e4410c1422a64 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Thu, 4 Jan 2024 02:24:13 +0100 Subject: [PATCH] Prefer build_unibyte_string where applicable * src/fns.c (syms_of_fns): * src/image.c (slurp_image): Prefer build_unibyte_string (str) to make_unibyte_string (str, strlen (str)). * admin/coccinelle/unibyte_string.cocci: Support string literals. --- admin/coccinelle/unibyte_string.cocci | 6 ++++++ src/fns.c | 2 +- src/image.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/admin/coccinelle/unibyte_string.cocci b/admin/coccinelle/unibyte_string.cocci index 0ff8cafa15d..97f87e5a4ca 100644 --- a/admin/coccinelle/unibyte_string.cocci +++ b/admin/coccinelle/unibyte_string.cocci @@ -4,3 +4,9 @@ identifier I; @@ - make_unibyte_string (I, strlen (I)) + build_unibyte_string (I) + +@@ +constant C; +@@ +- make_unibyte_string (C, strlen (C)) ++ build_unibyte_string (C) diff --git a/src/fns.c b/src/fns.c index 05b7fe85601..c03aea02397 100644 --- a/src/fns.c +++ b/src/fns.c @@ -6337,7 +6337,7 @@ The same variable also affects the function `read-answer'. See also DEFVAR_LISP ("yes-or-no-prompt", Vyes_or_no_prompt, doc: /* String to append when `yes-or-no-p' asks a question. For best results this should end in a space. */); - Vyes_or_no_prompt = make_unibyte_string ("(yes or no) ", strlen ("(yes or no) ")); + Vyes_or_no_prompt = build_unibyte_string ("(yes or no) "); defsubr (&Sidentity); defsubr (&Srandom); diff --git a/src/image.c b/src/image.c index dea2730832b..252b83da992 100644 --- a/src/image.c +++ b/src/image.c @@ -4373,7 +4373,7 @@ slurp_image (Lisp_Object filename, ptrdiff_t *size, const char *image_type) char *result = slurp_file (fd, size); if (result == NULL) image_error ("Error loading %s image `%s'", - make_unibyte_string (image_type, strlen (image_type)), + build_unibyte_string (image_type), file); return result; } -- 2.39.2