# Avoid subtraction overflow when excerpt primary is outside of excerpt… \(\#24213\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/27d1c689cf8a772cf0ebbb9eee51619b3fe4f7fc)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 27d1c689cf8a772cf0ebbb9eee51619b3fe4f7fc

Requested commit: 27d1c689cf8a772cf0ebbb9eee51619b3fe4f7fc

Commit: 27d1c689cf8a772cf0ebbb9eee51619b3fe4f7fc

Tree: f2ec27d088683a6bcdeed08dc43a384c692a1203

Author: Max Brunsfeld

Committer: GitHub

## Message

```
Avoid subtraction overflow when excerpt primary is outside of excerpt… (#24213)

This fixes a "subtract with overflow" error that could happen in debug
mode when viewing the project diagnostics.

From git bisecting, I think that this behavior was introduced by
https://github.com/zed-industries/zed/pull/21942. It seems like it's
possible in some cases for the excerpt-expansion heuristic to cause the
excerpt's `context` range to start *after* the excerpt's `primary`
range. We should probably revisit that heuristic at some point, but it
also seems reasonable to handle that situation at this layer, rather
than overflowing.

Release Notes:

- N/A
```

## Parents

- [4ab4e87266f935db5021ac9101c49240813f5c97](https://git.cafe/gitcafe/zed/commit/4ab4e87266f935db5021ac9101c49240813f5c97?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/27d1c689cf8a772cf0ebbb9eee51619b3fe4f7fc?format=markdown)
