Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/string/swab.c
Show All 37 Lines | |||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <unistd.h> | #include <unistd.h> | ||||
void | void | ||||
swab(const void * __restrict from, void * __restrict to, ssize_t len) | swab(const void * __restrict from, void * __restrict to, ssize_t len) | ||||
{ | { | ||||
unsigned long temp; | unsigned char temp; | ||||
int n; | size_t n; | ||||
char *fp, *tp; | const unsigned char *fp; | ||||
unsigned char *tp; | |||||
if (len <= 0) | if (len <= 0) | ||||
jrtc27: 1 works fine, it trivially ends up doing nothing. 0 does also, but that doesn't matter, the… | |||||
Done Inline ActionsDon't mark this as done if you haven't done it jrtc27: Don't mark this as done if you haven't done it | |||||
Done Inline ActionsChanging len < 2 to len <= 1 has no effect and is clearly therefore not what I meant. I meant remove the unnecessary change entirely. jrtc27: Changing `len < 2` to `len <= 1` has no effect and is clearly therefore not what I meant. I… | |||||
Done Inline ActionsAddressed! gfunni234_gmail.com: Addressed! | |||||
return; | return; | ||||
n = len >> 1; | n = (size_t)len >> 1; | ||||
fp = (char *)from; | fp = (const unsigned char *)from; | ||||
tp = (char *)to; | tp = (unsigned char *)to; | ||||
Done Inline ActionsSo just make n a ssize_t or a size_t (since negative len gets an early return)? Please learn to make your changes minimal, not change the whole thing just because you feel like it. jrtc27: So just make n a ssize_t or a size_t (since negative len gets an early return)? Please learn to… | |||||
Done Inline ActionsI thought less was more but ok. gfunni234_gmail.com: I thought less was more but ok. | |||||
Done Inline ActionsYes. Change less. jrtc27: Yes. Change less. | |||||
#define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp | #define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp | ||||
/* round to multiple of 8 */ | /* round to multiple of 8 */ | ||||
for (; n & 0x7; --n) | for (; n & 0x7; --n) | ||||
STEP; | STEP; | ||||
for (n >>= 3; n > 0; --n) { | for (n >>= 3; n > 0; --n) { | ||||
STEP; STEP; STEP; STEP; | STEP; STEP; STEP; STEP; | ||||
STEP; STEP; STEP; STEP; | STEP; STEP; STEP; STEP; | ||||
} | } | ||||
} | } |
1 works fine, it trivially ends up doing nothing. 0 does also, but that doesn't matter, the point is you don't need to touch this line.