private static int getMaxStringLength(Program program, Address address, int maxLen) {
		AddressIterator refIter =
			program.getReferenceManager().getReferenceDestinationIterator(address.next(), true);

		Address next = refIter.next();
		if (next == null) {
			return -1;
		}

		long len = -1;
		try {
			len = next.subtract(address);
			if (len > maxLen) {
				len = maxLen;
			}
			return (int) len;
		}
		catch (IllegalArgumentException e) {
			// bad address subtraction
		}

		return (int) len;
	}
Get the number of bytes to the next reference, or the max length
@param program The {@link Program}
@param address The {@link Address}
@param maxLen The maximum length
@return maximum length to create the string
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/RustStringAnalyzer.java