aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0006-fix-handling-of-odd-lengths-in-swab-function.patch
blob: ca144e59024ef0d69a49d39ed045cf079780012b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
From dccbf4c809efc311aa37da71de70d04dfd8b0db3 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Sat, 4 Oct 2014 11:14:01 -0400
Subject: [PATCH] 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.
---
 src/string/swab.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/string/swab.c b/src/string/swab.c
index 9ed6fcd..ace0f46 100644
--- a/src/string/swab.c
+++ b/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;
-- 
2.3.3