class DataUtilities {

	public static Address getMaxAddressOfUndefinedRange(Program program, Address addr) {
		Listing listing = program.getListing();
		Data data = listing.getDataContaining(addr);
		if (data == null || !Undefined.isUndefined(data.getDataType())) {
			return null;
		}
		Address endOfRangeAddress = data.getMaxAddress();

		MemoryBlock block = program.getMemory().getBlock(addr);
		if (block == null) {
			return null;
		}
		Address limitAddress = block.getEnd();

		CodeUnit cu = data;
		while (cu != null) {
			if (cu.getAddress().compareTo(limitAddress) > 0) {
				endOfRangeAddress = limitAddress;
				break;
			}
			if (!(cu instanceof Data) || !Undefined.isUndefined(((Data) cu).getDataType())) {
				endOfRangeAddress = cu.getMinAddress().previous();
				break;
			}
			endOfRangeAddress = cu.getMaxAddress();
			cu = listing.getDefinedCodeUnitAfter(endOfRangeAddress);
		}
		if (cu == null) {
			endOfRangeAddress = limitAddress;
		}

		return endOfRangeAddress;
	}

	private  DataUtilities();

}