[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Simplify string concatenations.
From: |
Tim Rühsen |
Subject: |
[PATCH] Simplify string concatenations. |
Date: |
Tue, 7 Apr 2020 20:01:33 +0200 |
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.
---
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..f4766bce 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)); \
\
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
- [PATCH] Simplify string concatenations.,
Tim Rühsen <=