Remove usages of old safe math #5829

Open
opened 2026-01-31 00:22:55 +00:00 by claunia · 3 comments
Owner

Originally created by @miniksa on GitHub (Jan 8, 2020).

There are approximately 79 uses of old safe math. (a.k.a. the LongAdd, ShortAdd, and friends from intsafe.h).

This task represents removing them and transitioning them to an appropriate safe/saturating math function from the chromium safe math library introduced in #4144.

After removing usages of the old safe math functions, also remove the intsafe.h header.

Files with old safe math as of this writing:

  • TerminalControl: TSFInputControl.cpp
  • TerminalCore: TerminalDispatch.cpp
  • TerminalCore: TerminalSelection.cpp
  • Host: directio.cpp
  • RendererGdi: invalidate.cpp
  • RendererGdi: math.cpp
  • RendererGdi: paint.cpp
  • RendererVt: paint.cpp
  • TerminalAdapter: adaptDispatch.cpp
  • Types: viewport.cpp
  • Types: WindowUiaProviderBase.cpp
Originally created by @miniksa on GitHub (Jan 8, 2020). There are approximately 79 uses of old safe math. (a.k.a. the `LongAdd`, `ShortAdd`, and friends from `intsafe.h`). This task represents removing them and transitioning them to an appropriate safe/saturating math function from the chromium safe math library introduced in #4144. After removing usages of the old safe math functions, also remove the `intsafe.h` header. Files with old safe math as of this writing: - TerminalControl: TSFInputControl.cpp - TerminalCore: TerminalDispatch.cpp - TerminalCore: TerminalSelection.cpp - Host: directio.cpp - RendererGdi: invalidate.cpp - RendererGdi: math.cpp - RendererGdi: paint.cpp - RendererVt: paint.cpp - TerminalAdapter: adaptDispatch.cpp - Types: viewport.cpp - Types: WindowUiaProviderBase.cpp
Author
Owner

@miniksa commented on GitHub (Jan 8, 2020):

If @j4james doesn't take this, whomever takes this should consult with @j4james on the ones in adaptDispatch.cpp because they should likely be saturating math instead of failing when exceeding bounds as they are today.

@miniksa commented on GitHub (Jan 8, 2020): If @j4james doesn't take this, whomever takes this should consult with @j4james on the ones in `adaptDispatch.cpp` because they should likely be saturating math instead of failing when exceeding bounds as they are today.
Author
Owner

@j4james commented on GitHub (Jan 8, 2020):

I don't mind doing this eventually, but I have bunch of stuff in progress that I would like to try and get finished first. If anyone else wants to take it on, though, I would recommend waiting at least until #3628 is merged, because there is a fair amount of safe math code in AdaptDispatch that will be nuked by that PR, so you'll be wasting your time if you're trying to refactor that.

On a similar note, I expect issue #3849 will end up replacing most, if not all, of the TerminalDispatch code. That said, it may be a long time before that happens, so it's possibly still worth cleaning up the existing code in the mean time.

@j4james commented on GitHub (Jan 8, 2020): I don't mind doing this eventually, but I have bunch of stuff in progress that I would like to try and get finished first. If anyone else wants to take it on, though, I would recommend waiting at least until #3628 is merged, because there is a fair amount of safe math code in `AdaptDispatch` that will be nuked by that PR, so you'll be wasting your time if you're trying to refactor that. On a similar note, I expect issue #3849 will end up replacing most, if not all, of the `TerminalDispatch` code. That said, it may be a long time before that happens, so it's possibly still worth cleaning up the existing code in the mean time.
Author
Owner

@j4james commented on GitHub (Jan 9, 2020):

One other thing I wanted to add: there is another category of intsafe routines which I think isn't covered by the 79 uses mentioned above, and that is the type conversion functions, e.g. SizeTToShort. In the VT code, I think many of those would probably need to be converted to something like a saturated_cast when using the new chromium lib.

@j4james commented on GitHub (Jan 9, 2020): One other thing I wanted to add: there is another category of intsafe routines which I think isn't covered by the 79 uses mentioned above, and that is the type conversion functions, e.g. `SizeTToShort`. In the VT code, I think many of those would probably need to be converted to something like a `saturated_cast` when using the new chromium lib.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#5829