poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Avoid malloc in pkl_trans1_ps_string


From: Tim Rühsen
Subject: [PATCH] Avoid malloc in pkl_trans1_ps_string
Date: Sat, 4 Apr 2020 19:49:05 +0200

2020-04-04  Tim Rühsen  <address@hidden>

        * src/pkl-trans.c (pkl_trans1_ps_string): Avoid malloc if string
        does not need escaping.
---
 ChangeLog       | 5 +++++
 src/pkl-trans.c | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/src/pkl-trans.c b/src/pkl-trans.c
index a91d9b3b..5b81a89e 100644
--- a/src/pkl-trans.c
+++ b/src/pkl-trans.c
@@ -269,6 +269,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_string)
   char *new_string_pointer;
   char *p;
   size_t string_length, i;
+  bool found_slash = false;

   /* Please keep this code in sync with the string printer in
      pvm-val.c:pvm_print_val.  */
@@ -294,11 +295,15 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_string)
               PKL_PASS_ERROR;
             }
           p++;
+          found_slash = true;
         }
       else
         string_length++;
     }

+  if (!found_slash)
+    goto _exit;
+
   /* Second pass: compose the new string.  */
   new_string_pointer = xmalloc (string_length + 1);

--
2.26.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]