Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wstring bugs in [L|R]TRIM functions #142

Merged
merged 5 commits into from May 5, 2019

Conversation

jayrm
Copy link
Member

@jayrm jayrm commented May 4, 2019

bugfix: sf.net #899 trim( wstring ) causes crash if string is single space

  • In fb_wstr_CalcDiff() the original expression is optimized with a SHR expression due the divide by unsigned power of 2. This doesn't work for negative values.
  • Casting to intptr_t should not be needed as the pointer arithmetic alone should be sufficient to calculate distance betwee related pointers
  • avoid returning a pointer before the first element in fb_wstr_SkipCharRev(), &s[-1] is undefined behaviour
  • also then avoids passing start > end pointers to fb_wstr_CalcDiff()
  • fb_wstr_SkipCharRev() now returns a pointer to the start of all skipped chars, or the end marker if no chars are skipped

bugfix: sf.net #900 LTRIM and TRIM truncate result if filter is zero length string

  • [L]TRIM( wstring, filter ) will return a zero length string if the filter is also a zero length string

jayrm added 5 commits May 4, 2019 21:10
…space

- In fb_wstr_CalcDiff() the original expression is optimized with a SHR expression due the divide by unsigned power of 2.  This doesn't work for negative values.
- Casting to intptr_t should not be needed as the pointer arithmetic alone should be sufficient to calculate distance betwee related pointers
…space

- avoid returning a pointer before the first element in fb_wstr_SkipCharRev(), &s[-1] is undefined behaviour
- also then avoids passing start > end pointers to fb_wstr_CalcDiff()
- fb_wstr_SkipCharRev() now returns a pointer to the start of all skipped chars, or the end marker if no chars are skipped
…length string

- [L]TRIM( wstring, filter ) will return a zero length string if the filter is also a zero length string
@jayrm jayrm merged commit 1937d58 into freebasic:master May 5, 2019
@jayrm jayrm deleted the bugfix-wstring branch May 5, 2019 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant