[PATCH] cpukit/libmisc/shell/shell.c: Fix restrict warning

Aschref Ben-Thabet aschref.ben-thabet at embedded-brains.de
Tue Sep 15 09:06:36 UTC 2020


From: Aschref Ben Thabet <aschref.ben-thabet at embedded-brains.de>

Replace the unsafe function strcpy() with memmove() to avoid the string
restrict warning.
Since memmove() function is used to copy a specified number of bytes
from one memory to another or to overlap on same memory.
---
 cpukit/libmisc/shell/shell.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index 13ae411f9c..36eac3d14f 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -393,7 +393,7 @@ static int rtems_shell_line_editor(
           {
             int end;
             int bs;
-            strcpy (&line[col], &line[col + 1]);
+            memmove(line + col, line + col + 1, strlen(line + col + 1) + 1);
             if (output) {
               fprintf(out,"\r%s%s ", prompt, line);
               end = (int) strlen (line);
@@ -432,7 +432,7 @@ static int rtems_shell_line_editor(
         case 4:                         /* Control-D */
           if (strlen(line)) {
             if (col < strlen(line)) {
-              strcpy (line + col, line + col + 1);
+              memmove(line + col, line + col + 1, strlen(line + col + 1) + 1);
               if (output) {
                 int bs;
                 fprintf(out,"%s \b", line + col);
@@ -508,7 +508,7 @@ static int rtems_shell_line_editor(
           {
             int bs;
             col--;
-            strcpy (line + col, line + col + 1);
+            memmove(line + col, line + col + 1, strlen(line + col + 1));
             if (output) {
               fprintf(out,"\b%s \b", line + col);
               for (bs = 0; bs < ((int) strlen (line) - col); bs++)
@@ -620,9 +620,9 @@ static int rtems_shell_line_editor(
         case 21:                        /* Control-U */
           if (col > 0)
           {
-            int clen = strlen (line);
+            size_t clen = strlen (line);
 
-            strcpy (line, line + col);
+            memmove(line, line + col, strlen(line + col) + 1);
             if (output) {
               fprintf(out,"\r%s%*c", prompt, clen, ' ');
               fprintf(out,"\r%s%s", prompt, line);
-- 
2.26.2



More information about the devel mailing list