[Android] libvlcjni: throw_Exception: use fmt and va_list

Thomas Guillem git at videolan.org
Fri Aug 24 09:20:56 CEST 2018


vlc-android | branch: 4.0-glrenderer | Thomas Guillem <thomas at gllm.fr> | Wed Aug 22 14:38:31 2018 +0200| [18029ae911ba2d418e0cf69f148e7e04f9c930b8] | committer: Thomas Guillem

libvlcjni: throw_Exception: use fmt and va_list

> https://code.videolan.org/videolan/vlc-android/commit/18029ae911ba2d418e0cf69f148e7e04f9c930b8
---

 libvlc/jni/libvlcjni-vlcobject.h | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/libvlc/jni/libvlcjni-vlcobject.h b/libvlc/jni/libvlcjni-vlcobject.h
index 56fe88cd2..1054cc100 100644
--- a/libvlc/jni/libvlcjni-vlcobject.h
+++ b/libvlc/jni/libvlcjni-vlcobject.h
@@ -97,8 +97,15 @@ enum vlcjni_exception
 };
 
 static inline void throw_Exception(JNIEnv *env, enum vlcjni_exception type,
-                                   const char *p_error)
+                                   const char *fmt, ...)
 {
+    va_list args;
+    va_start(args, fmt);
+
+    char *error;
+    if (vasprintf(&error, fmt, args) == -1)
+        error = NULL;
+
     jclass clazz;
     switch (type)
     {
@@ -113,7 +120,10 @@ static inline void throw_Exception(JNIEnv *env, enum vlcjni_exception type,
             clazz = fields.IllegalArgumentException.clazz;
             break;
     }
-    (*env)->ThrowNew(env, clazz, p_error);
+    (*env)->ThrowNew(env, clazz, error ? error : fmt);
+
+    free(error);
+    va_end(args);
 }
 
 #endif // LIBVLCJNI_VLCOBJECT_H



More information about the Android mailing list