From 0b15418d92dbbbc22bdf6fe0655d27ea0473c522 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Wed, 6 Jan 2016 13:01:24 -0800 Subject: [PATCH] snprintf off by one. Summary: According to `man snprintf` Upon successful return, these functions return the number of characters printed (not including the trailing '\0' used to end output to strings). Or am I misunderstanding something about what's going on here? public Reviewed By: zlern2k, dcolascione Differential Revision: D2805759 fb-gh-sync-id: f20908f80cdfff9677fe38c7c1cf733f0f5b1c5e --- ReactAndroid/src/main/jni/first-party/jni/fbjni/Exceptions.cpp | 2 +- ReactAndroid/src/main/jni/first-party/jni/fbjni/Exceptions.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/jni/first-party/jni/fbjni/Exceptions.cpp b/ReactAndroid/src/main/jni/first-party/jni/fbjni/Exceptions.cpp index 20925ae80..710a6836f 100644 --- a/ReactAndroid/src/main/jni/first-party/jni/fbjni/Exceptions.cpp +++ b/ReactAndroid/src/main/jni/first-party/jni/fbjni/Exceptions.cpp @@ -193,7 +193,7 @@ void setNewJavaException(jclass exceptionClass, const char* fmt, ARGS... args) { JNIEnv* env = internal::getEnv(); try { - char *msg = (char*) alloca(msgSize); + char *msg = (char*) alloca(msgSize + 1); snprintf(msg, kMaxExceptionMessageBufferSize, fmt, args...); env->ThrowNew(exceptionClass, msg); } catch (...) { diff --git a/ReactAndroid/src/main/jni/first-party/jni/fbjni/Exceptions.h b/ReactAndroid/src/main/jni/first-party/jni/fbjni/Exceptions.h index 9ba9367f6..1892fd49c 100644 --- a/ReactAndroid/src/main/jni/first-party/jni/fbjni/Exceptions.h +++ b/ReactAndroid/src/main/jni/first-party/jni/fbjni/Exceptions.h @@ -114,7 +114,7 @@ template assertIfExceptionsNotInitialized(); int msgSize = snprintf(nullptr, 0, fmt, args...); - char *msg = (char*) alloca(msgSize); + char *msg = (char*) alloca(msgSize + 1); snprintf(msg, kMaxExceptionMessageBufferSize, fmt, args...); throwNewJavaException(throwableName, msg); }