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
This commit is contained in:
Родитель
0f9c88514c
Коммит
0b15418d92
|
@ -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 (...) {
|
||||
|
|
|
@ -114,7 +114,7 @@ template<typename... Args>
|
|||
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);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче