3.4.5 How Can I Prevent Misuse of My Code?
First, many devices with flash program memory allow all or part of this memory to be write protected. The device configuration bits need to be set correctly for this to take place (see 7.3 Configuration Bit Access and your device data sheet).
Second, you can prevent third-party code being programmed at unused locations in the program memory by filling these locations with a value rather than leaving them in their default unprogrammed state. You can chose a fill value that corresponds to an instruction or set all the bits so as the values cannot be further modified. Consider what will happen if your program somehow reaches and starts executing from these filled values (what instruction will be executed?).
The fill-memory feature is not yet available for the PIC32C/SAM compiler.