texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Mon, 13 Nov 2023 09:05:15 -0500 (EST)

branch: master
commit dafd844d7fa7c950d1ba8e171baa58e7d997b369
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Nov 13 14:22:59 2023 +0100

    * tp/Texinfo/XS/main/node_name_normalization.c (normalize_top_name)
    (convert_to_identifier): never free input of normalize_top_name,
    result always need to be freed.
    
    * tp/Texinfo/XS/main/node_name_normalization.c (normalize_top_name)
    (unicode_to_protected, protect_unicode_char): set input text to be
    const.
---
 ChangeLog                                    | 10 +++++++++
 tp/Texinfo/XS/main/node_name_normalization.c | 33 ++++++++++++++++++----------
 2 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bfc220f409..56e1de8c63 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2023-11-13  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/node_name_normalization.c (normalize_top_name)
+       (convert_to_identifier): never free input of normalize_top_name,
+       result always need to be freed.
+
+       * tp/Texinfo/XS/main/node_name_normalization.c (normalize_top_name)
+       (unicode_to_protected, protect_unicode_char): set input text to be
+       const.
+
 2023-11-13  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/parsetexi/def.c (split_delimiters, split_def_args),
diff --git a/tp/Texinfo/XS/main/node_name_normalization.c 
b/tp/Texinfo/XS/main/node_name_normalization.c
index 11462e59e7..35c30df3bb 100644
--- a/tp/Texinfo/XS/main/node_name_normalization.c
+++ b/tp/Texinfo/XS/main/node_name_normalization.c
@@ -184,7 +184,7 @@ convert_to_normalized (ELEMENT *e)
 }
 
 void
-protect_unicode_char (char *text, TEXT *result)
+protect_unicode_char (const char *text, TEXT *result)
 {
   uint8_t *encoded_u8;
   const uint8_t *next;
@@ -213,10 +213,11 @@ protect_unicode_char (char *text, TEXT *result)
   free (str);
 }
 
-char *unicode_to_protected (char *text)
+/* to be freed by caller */
+char *unicode_to_protected (const char *text)
 {
   TEXT result;
-  char *p = text;
+  const char *p = text;
 
   text_init (&result);
   text_append (&result, "");
@@ -256,28 +257,35 @@ char *unicode_to_protected (char *text)
   return (result.text);
 }
 
-/* frees input if another string is returned */
-char *normalize_top_name (char *text)
+/* to be freed by caller */
+char *normalize_top_name (const char *text)
 {
-  char *result = text;
-  if (strlen(text) == 3)
+  if (strlen (text) == 3)
     {
       char *normalized = strdup (text);
       char *p;
 
       for (p = normalized; *p; p++)
-        if (isascii_alnum(*p))
-          *p = tolower (*p);
+        if (isascii_alnum (*p))
+          {
+            *p = tolower (*p);
+          }
+        else
+          {
+            free (normalized);
+            return strdup (text);
+          }
 
       if (!strcmp (normalized, "top"))
         {
-          result = strdup ("Top");
-          free (text);
+          free (normalized);
+          return strdup ("Top");
         }
 
       free (normalized);
+      return strdup (text);
     }
-  return result;
+  return strdup (text);
 }
 
 char *
@@ -288,6 +296,7 @@ convert_to_identifier (ELEMENT *root)
   char *protected = unicode_to_protected (normalized_name);
   char *result = normalize_top_name (protected);
 
+  free (protected);
   free (converted_name);
   free (normalized_name);
   return result;



reply via email to

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