am a5608acb: Merge "Don\'t allow MemoryFiles of negative length."
* commit 'a5608acbd7647e0fd9aa87e5319715b0cbd6b0c0': Don't allow MemoryFiles of negative length.
This commit is contained in:
@@ -63,12 +63,17 @@ public class MemoryFile
|
|||||||
* Allocates a new ashmem region. The region is initially not purgable.
|
* Allocates a new ashmem region. The region is initially not purgable.
|
||||||
*
|
*
|
||||||
* @param name optional name for the file (can be null).
|
* @param name optional name for the file (can be null).
|
||||||
* @param length of the memory file in bytes.
|
* @param length of the memory file in bytes, must be non-negative.
|
||||||
* @throws IOException if the memory file could not be created.
|
* @throws IOException if the memory file could not be created.
|
||||||
*/
|
*/
|
||||||
public MemoryFile(String name, int length) throws IOException {
|
public MemoryFile(String name, int length) throws IOException {
|
||||||
mLength = length;
|
mLength = length;
|
||||||
|
if (length >= 0) {
|
||||||
mFD = native_open(name, length);
|
mFD = native_open(name, length);
|
||||||
|
} else {
|
||||||
|
throw new IOException("Invalid length: " + length);
|
||||||
|
}
|
||||||
|
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
mAddress = native_mmap(mFD, length, PROT_READ | PROT_WRITE);
|
mAddress = native_mmap(mFD, length, PROT_READ | PROT_WRITE);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user