Преглед на файлове

fix handling of odd lengths in swab function

this function is specified to leave the last byte with "unspecified
disposition" when the length is odd, so for the most part correct
programs should not be calling swab with odd lengths. however, doing
so is permitted, and should not write past the end of the destination
buffer.
Rich Felker преди 10 години
родител
ревизия
dccbf4c809
променени са 1 файла, в които са добавени 1 реда и са изтрити 1 реда
  1. 1 1
      src/string/swab.c

+ 1 - 1
src/string/swab.c

@@ -4,7 +4,7 @@ void swab(const void *restrict _src, void *restrict _dest, ssize_t n)
 {
 	const char *src = _src;
 	char *dest = _dest;
-	for (; n>0; n-=2) {
+	for (; n>1; n-=2) {
 		dest[0] = src[1];
 		dest[1] = src[0];
 		dest += 2;