protected long computeTruncatedMax(Lifespan lifespan, T extending, AddressRange range)
			throws CodeUnitInsertionException {
		// First, truncate lifespan to the next code unit when upper bound is max
		if (!lifespan.maxIsFinite()) {
			lifespan = space.instructions.truncateSoonestDefined(lifespan, extending, range);
			lifespan = space.definedData.truncateSoonestDefined(lifespan, extending, range);
		}
		// Second, truncate lifespan to the next change of bytes in the range
		DBTraceMemorySpace memSpace =
			space.trace.getMemoryManager().getMemorySpace(space.space, true);
		Lifespan fullSpan = extending == null ? lifespan : lifespan.bound(extending.getLifespan());
		long endSnap = memSpace.getFirstChange(fullSpan, range);
		if (endSnap == Long.MIN_VALUE) {
			return lifespan.lmax();
		}
		return endSnap - 1;
	}
Select a sub-lifespan from that given so that the box does not overlap an existing unit

<p>
The selected lifespan will have the same start snap as that given. The box is the bounding
box of a unit the client is trying to create.

@param span the lifespan of the box
@param extending if applicable, the unit whose lifespan is being extended
@param range the address range of the box
@return the selected sub-lifespan
@throws CodeUnitInsertionException if the start snap is contained in an existing unit
Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/AbstractBaseDBTraceDefinedUnitsView.java