Skip to content

Commit f0143f9

Browse files
committed
Fix String::remove warning
Replace strncpy() usage in String::remove method by memmove(). Destination and source shall not overlap when using strncpy() while memmove() is safer alternative when overlapping. Warning raised after moved from arm-none-eabi-gcc 6-2017-q2-update to 8-2018-q4-major: cores\arduino\WString.cpp: In member function 'void String::remove(unsigned int, unsigned int)': cores\arduino\WString.cpp:832:10: warning: 'char* strncpy(char*, const char*, size_t)' accessing 0 or more bytes at offsets [0, 2147483647] and [0, 2147483647] may overlap up to 4294967295 bytes at offset [6442450941, 2147483647] [-Wrestrict] strncpy(writeTo, buffer + index + count, len - index); ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 49eb0b8 commit f0143f9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

cores/arduino/WString.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ void String::remove(unsigned int index, unsigned int count)
829829
}
830830
char *writeTo = buffer + index;
831831
len = len - count;
832-
strncpy(writeTo, buffer + index + count, len - index);
832+
memmove(writeTo, buffer + index + count, len - index);
833833
buffer[len] = 0;
834834
}
835835

0 commit comments

Comments
 (0)