[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Simplify string concatenations.
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH] Simplify string concatenations. |
Date: |
Tue, 07 Apr 2020 20:08:29 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Hi Tim.
2020-04-07 Tim Rühsen <address@hidden>
* src/pkl-fold.c (OP_BINARY_SSS): Use pk_str_concat instead of
strlen/xmalloc/strcpy/strcat.
* src/pkl.c (pkl_new): Likewise.
OK for master.
Thanks!
---
ChangeLog | 6 ++++++
src/pkl-fold.c | 8 ++------
src/pkl.c | 6 +-----
3 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/src/pkl-fold.c b/src/pkl-fold.c
index 593bd6c8..a00ad787 100644
--- a/src/pkl-fold.c
+++ b/src/pkl-fold.c
@@ -582,12 +582,8 @@ EMUL_UU (bnoto) { return ~op; }
/* We cannot fold this expression. */ \
PKL_PASS_DONE; \
\
- res = xmalloc (strlen (PKL_AST_STRING_POINTER (op1)) \
- + strlen (PKL_AST_STRING_POINTER (op2)) \
- + 1); \
- \
- strcpy (res, PKL_AST_STRING_POINTER (op1)); \
- strcat (res, PKL_AST_STRING_POINTER (op2)); \
+ res = pk_str_concat (PKL_AST_STRING_POINTER (op1), \
+ PKL_AST_STRING_POINTER (op2), NULL); \
\
new = pkl_ast_make_string (PKL_PASS_AST, res); \
free (res); \
diff --git a/src/pkl.c b/src/pkl.c
index a83beaaf..84874a70 100644
--- a/src/pkl.c
+++ b/src/pkl.c
@@ -79,11 +79,7 @@ pkl_new (pvm vm, const char *rt_path)
/* Bootstrap the compiler. An error bootstraping is an internal
error and should be reported as such. */
{
- char *poke_rt_pk;
-
- poke_rt_pk = xmalloc (strlen (rt_path) + strlen ("/pkl-rt.pk") + 1);
- strcpy (poke_rt_pk, rt_path);
- strcat (poke_rt_pk, "/pkl-rt.pk");
+ char *poke_rt_pk = pk_str_concat (rt_path, "/pkl-rt.pk", NULL);
if (!pkl_compile_file (compiler, poke_rt_pk))
{
--
2.26.0