WARNING: This server is unstable and will be retired in the next days. If you want to keep this forum available, please request immediately a migration on the Nabble Support forum. Forums that don't receive any migration request will be deleted forever.

FYI: [PATCH] Fix Java_java_nio_VMDirectByteBuffer_allocate() for negative capacity

View: New views
2 Messages — Rating Filter:   Alert me  

FYI: [PATCH] Fix Java_java_nio_VMDirectByteBuffer_allocate() for negative capacity

by Pekka Enberg-4 :: Rate this Message:

| View Threaded | Show Only this Message

JavaDocs clearly state that ByteBuffer.allocateDirect() must throw
IllegalArgumentException if capacity is negative.

2011-03-17  Pekka Enberg  <penberg@...>

        * native/jni/java-nio/java_nio_VMDirectByteBuffer.c:
        (Java_java_nio_VMDirectByteBuffer_allocate): Check for negative
        capacity.

---
 native/jni/java-nio/java_nio_VMDirectByteBuffer.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/native/jni/java-nio/java_nio_VMDirectByteBuffer.c b/native/jni/java-nio/java_nio_VMDirectByteBuffer.c
index bfee7e9..7325c5b 100644
--- a/native/jni/java-nio/java_nio_VMDirectByteBuffer.c
+++ b/native/jni/java-nio/java_nio_VMDirectByteBuffer.c
@@ -51,6 +51,13 @@ Java_java_nio_VMDirectByteBuffer_allocate
 {
   void *buffer;
 
+  if (capacity < 0)
+    {
+      JCL_ThrowException (env, "java/lang/IllegalArgumentException",
+  "negative capacity");
+      return 0;
+    }
+
   buffer = malloc (capacity);
 
   if (buffer == NULL)
--
1.7.1



Re: FYI: [PATCH] Fix Java_java_nio_VMDirectByteBuffer_allocate() for negative capacity

by gnu_andrew :: Rate this Message:

| View Threaded | Show Only this Message

On 17 March 2011 19:52, Pekka Enberg <penberg@...> wrote:

> JavaDocs clearly state that ByteBuffer.allocateDirect() must throw
> IllegalArgumentException if capacity is negative.
>
> 2011-03-17  Pekka Enberg  <penberg@...>
>
>        * native/jni/java-nio/java_nio_VMDirectByteBuffer.c:
>        (Java_java_nio_VMDirectByteBuffer_allocate): Check for negative
>        capacity.
>
> ---
>  native/jni/java-nio/java_nio_VMDirectByteBuffer.c |    7 +++++++
>  1 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/native/jni/java-nio/java_nio_VMDirectByteBuffer.c b/native/jni/java-nio/java_nio_VMDirectByteBuffer.c
> index bfee7e9..7325c5b 100644
> --- a/native/jni/java-nio/java_nio_VMDirectByteBuffer.c
> +++ b/native/jni/java-nio/java_nio_VMDirectByteBuffer.c
> @@ -51,6 +51,13 @@ Java_java_nio_VMDirectByteBuffer_allocate
>  {
>   void *buffer;
>
> +  if (capacity < 0)
> +    {
> +      JCL_ThrowException (env, "java/lang/IllegalArgumentException",
> +                         "negative capacity");
> +      return 0;
> +    }
> +
>   buffer = malloc (capacity);
>
>   if (buffer == NULL)
> --
> 1.7.1
>
>
>

Maybe it would be better to do this in DirectByteBufferImpl.java ?
--
Andrew :-)

Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)

Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net

PGP Key: F5862A37 (https://keys.indymedia.org/)
Fingerprint = EA30 D855 D50F 90CD F54D  0698 0713 C3ED F586 2A37