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.
Tags
None
Referenced Files
F81663633: D31638.diff
Fri, Apr 19, 3:47 PM
Unknown Object (File)
Tue, Apr 9, 7:47 PM
Unknown Object (File)
Tue, Apr 9, 7:20 PM
Unknown Object (File)
Feb 11 2024, 6:39 AM
Unknown Object (File)
Feb 8 2024, 6:32 PM
Unknown Object (File)
Jan 17 2024, 6:14 PM
Unknown Object (File)
Dec 22 2023, 11:57 PM
Unknown Object (File)
Dec 13 2023, 12:10 AM
Subscribers
None

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
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!