Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144456991
D48259.1774705797.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
822 B
Referenced Files
None
Subscribers
None
D48259.1774705797.diff
View Options
diff --git a/lib/libc/string/swab.c b/lib/libc/string/swab.c
--- a/lib/libc/string/swab.c
+++ b/lib/libc/string/swab.c
@@ -4,19 +4,22 @@
*/
#include <unistd.h>
+#include <sys/endian.h>
void
swab(const void * __restrict from, void * __restrict to, ssize_t len)
{
- const unsigned char *f = from;
- unsigned char *t = to;
+ const uint16_t *f __aligned(1) = from;
+ uint16_t *t __aligned(1) = to;
+ /*
+ * POSIX says overlapping copy behavior is undefined, however many
+ * applications assume the old FreeBSD and current GNU libc behavior
+ * that will swap the bytes correctly when from == to. Reading both bytes
+ * and swapping them before writing them back accomplishes this.
+ */
while (len > 1) {
- t[0] = f[1];
- t[1] = f[0];
-
- f += 2;
- t += 2;
+ *t++ = bswap16(*f++);
len -= 2;
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 28, 1:49 PM (22 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28218366
Default Alt Text
D48259.1774705797.diff (822 B)
Attached To
Mode
D48259: swab: Fix implementation to support overlapping copies
Attached
Detach File
Event Timeline
Log In to Comment