One of the gcc warnings points to an actual bug:

../../gllib/astrxfrm.c:159:19: warning: pointer 'result' may be used after 
'realloc' [-Wuse-after-free]

This patch fixes it.


2023-05-18  Bruno Haible  <br...@clisp.org>

        astrxfrm: Fix use-after-free bug.
        * lib/astrxfrm.c (astrxfrm): Don't use memcpy after realloc succeeded.

diff --git a/lib/astrxfrm.c b/lib/astrxfrm.c
index 214ebc38b8..845f0a0711 100644
--- a/lib/astrxfrm.c
+++ b/lib/astrxfrm.c
@@ -155,10 +155,7 @@ astrxfrm (const char *s, char *resultbuf, size_t *lengthp)
             {
               char *memory = (char *) realloc (result, length);
               if (memory != NULL)
-                {
-                  memcpy (memory, result, length);
-                  result = memory;
-                }
+                result = memory;
             }
         }
     }




Reply via email to