Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F173763918
D54399.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
803 B
Referenced Files
None
Subscribers
None
D54399.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
@@ -3,14 +3,16 @@
* Copyright (c) 2024 rilysh <nightquick@proton.me>
*/
+#include <string.h>
#include <unistd.h>
#include <sys/endian.h>
void
swab(const void * __restrict from, void * __restrict to, ssize_t len)
{
- const uint16_t *f __aligned(1) = from;
- uint16_t *t __aligned(1) = to;
+ const char *f = from;
+ char *t = to;
+ uint16_t tmp;
/*
* POSIX says overlapping copy behavior is undefined, however many
@@ -19,7 +21,12 @@
* and swapping them before writing them back accomplishes this.
*/
while (len > 1) {
- *t++ = bswap16(*f++);
+ memcpy(&tmp, f, 2);
+ tmp = bswap16(tmp);
+ memcpy(t, &tmp, 2);
+
+ f += 2;
+ t += 2;
len -= 2;
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Sep 29, 5:42 AM (53 m, 59 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39860730
Default Alt Text
D54399.diff (803 B)
Attached To
Mode
D54399: swab: Correctly treat the data as misaligned
Attached
Detach File
Event Timeline
Log In to Comment