private 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 exc) {
			// bad address subtraction
		}
		return (int) len;
	}
Get the number of bytes to the next reference, or the max length

@param program
@param address
@return maximum length to create the string
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/ConstantPropagationContextEvaluator.java