cpukit/libmisc/monitor: Fix an illegal string copy

This is actually an illegal use of strcpy() because one is not allowed to
use this function with overlapping source and destination buffers; whereas
memmove() is explicitly designed to handle such cases.

The compiler warning was:

../../../cpukit/libmisc/monitor/mon-editor.c:342:15: warning:
'strcpy' accessing 1 byte at offsets [0, 75] and [0, 75] overlaps
1 byte at offset [0, 74] [-Wrestrict]
This commit is contained in:
Frank Kühndel
2020-10-05 16:49:14 +02:00
committed by Sebastian Huber
parent 4763ef8d9b
commit f3df25b65c

View File

@@ -339,7 +339,8 @@ rtems_monitor_line_editor (
{
int end;
int bs;
strcpy (&buffer[pos], &buffer[pos + 1]);
memmove (&buffer[pos], &buffer[pos + 1],
strlen (&buffer[pos + 1]) + 1);
fprintf(stdout,"\r%s $ %s", monitor_prompt, buffer);
end = (int) strlen (buffer);
for (bs = 0; bs < (end - pos); bs++)