Page MenuHomeFreeBSD

[libc] Optimize swab so that it can handle any ssize_t value
Needs ReviewPublic

Authored by gfunni234_gmail.com on Aug 22 2021, 6:56 PM.

Details

Reviewers
imp
jrtc27
dim
Summary

Casting to int cuts off data on some platforms for some sizes, resulting in the incorrect results for swab.

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

gfunni234_gmail.com created this revision.
gfunni234_gmail.com retitled this revision from Optimize swab so that it can handle any ssize_t value to [libc] Optimize swab so that it can handle any ssize_t value.
gfunni234_gmail.com added a reviewer: imp.
lib/libc/string/swab.c
51

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.

53–55

So 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.

gfunni234_gmail.com added inline comments.
lib/libc/string/swab.c
53–55

I thought less was more but ok.

lib/libc/string/swab.c
53–55

Yes. Change less.

gfunni234_gmail.com marked 2 inline comments as done.

Addressed issues!

lib/libc/string/swab.c
51

Don't mark this as done if you haven't done it

gfunni234_gmail.com marked an inline comment as not done.
gfunni234_gmail.com marked 2 inline comments as done.
lib/libc/string/swab.c
51

Changing len < 2 to len <= 1 has no effect and is clearly therefore not what I meant. I meant remove the unnecessary change entirely.

lib/libc/string/swab.c
51

Addressed!