private int getValidPadLength(Program program, Address stringEndAddress, int padLength) {

		Listing listing = program.getListing();
		Address address = stringEndAddress;

		for (int i = 0; i < padLength; i++) {
			address = address.next();
			if (address == null) {
				return 0;
			}
			CodeUnit cu = listing.getCodeUnitContaining(address);
			if (cu == null) {
				return 0; // null implies there cannot be data here
			}

			if (!(cu instanceof Data) || ((Data) cu).isDefined()) {
				return 0;
			}
		}

		return padLength;
	}
Verify that adding padding bytes won't violate boundaries or allow defined data
or instructions to be overwritten.

@param program		current program
@param stringEndAddress	strings' end address
@param padLength		number of pad bytes
@return	actual number of pad bytes to add to the string
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/string/StringsAnalyzer.java