Skip to content

Commit

Permalink
Fix conversion from double to int16_t in JSC bindings
Browse files Browse the repository at this point in the history
Summary:
Converting from double to int16_t is undefined behavior if the value
doesn't fit in int16_t.

Reviewed By: tmikov

Differential Revision: D8925246

fbshipit-source-id: 4cf57631686a4ce05546f8d30a46e3f9def3aee2
  • Loading branch information
Simon Jensen authored and facebook-github-bot committed Jul 24, 2018
1 parent 8116c3f commit 17485e8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ReactAndroid/src/main/jni/react/jni/JSCPerfLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ static JSValueRef nativeQPLMarkerEnd(
if (isReady() && grabDoubles(4, targets, ctx, argumentCount, arguments, exception)) {
int32_t markerId = (int32_t) targets[0];
int32_t instanceKey = (int32_t) targets[1];
int16_t actionId = (int16_t) targets[2];
// NOTE: avoid undefined behavior when the value does not find in int16_t.
int16_t actionId = (int16_t) (int32_t) targets[2];
int64_t timestamp = (int64_t) targets[3];
JQuickPerformanceLoggerProvider::get()->markerEnd(markerId, instanceKey, actionId, timestamp);
}
Expand Down Expand Up @@ -230,7 +231,8 @@ static JSValueRef nativeQPLMarkerNote(
if (isReady() && grabDoubles(4, targets, ctx, argumentCount, arguments, exception)) {
int32_t markerId = (int32_t) targets[0];
int32_t instanceKey = (int32_t) targets[1];
int16_t actionId = (int16_t) targets[2];
// NOTE: avoid undefined behavior when the value does not find in int16_t.
int16_t actionId = (int16_t) (int32_t) targets[2];
int64_t timestamp = (int64_t) targets[3];
JQuickPerformanceLoggerProvider::get()->markerNote(markerId, instanceKey, actionId, timestamp);
}
Expand Down

0 comments on commit 17485e8

Please sign in to comment.