From 1e90da4225c52e106f7fa11fcfb2f87bd08e0c79 Mon Sep 17 00:00:00 2001 From: Ripinder Singh Date: Wed, 15 Oct 2025 09:35:25 +1100 Subject: [PATCH] Fix for crash in debug mode in macos when reading windows stlye line ending * remove_cr() utilizes strcpy with overlapped memory * strcpy with overlapping buffers results in undefined behavior in C * Entire buffer movement is needlessly expensinve Signed-off-by: Ripinder Singh --- lib_util/cmdl_tools.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_util/cmdl_tools.c b/lib_util/cmdl_tools.c index bec772ce42..625db12733 100644 --- a/lib_util/cmdl_tools.c +++ b/lib_util/cmdl_tools.c @@ -185,16 +185,16 @@ void convert_backslash( void remove_cr( char *str ) { - char *pos; + int32_t n, p = 0; /* remove all \r characters from the string */ - pos = strchr( str, '\r' ); - while ( pos != NULL ) + for ( n = 0; str[n] != 0; n++ ) { - strcpy( pos, pos + 1 ); - pos = strchr( pos, '\r' ); + char c = str[n]; + str[p] = c; + p += ( c == '\r' ) ? 0 : 1; } - + str[p] = 0; return; } -- GitLab