Skip to content

Commit dc6dac5

Browse files
committed
Add npe checker for string pointer
1 parent dbf41d3 commit dc6dac5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

internal/internal_event_handlers.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,13 +1411,13 @@ func (weh *workflowExecutionEventHandlerImpl) estimateHistorySize(event *m.Histo
14111411
}
14121412
case m.EventTypeDecisionTaskStarted:
14131413
if event.DecisionTaskStartedEventAttributes != nil {
1414-
sum += len(*event.DecisionTaskStartedEventAttributes.Identity)
1414+
sum += getLengthOfStringPointer(event.DecisionTaskStartedEventAttributes.Identity)
14151415
}
14161416
case m.EventTypeDecisionTaskCompleted:
14171417
if event.DecisionTaskCompletedEventAttributes != nil {
14181418
sum += len(event.DecisionTaskCompletedEventAttributes.ExecutionContext)
1419-
sum += len(*event.DecisionTaskCompletedEventAttributes.Identity)
1420-
sum += len(*event.DecisionTaskCompletedEventAttributes.BinaryChecksum)
1419+
sum += getLengthOfStringPointer(event.DecisionTaskCompletedEventAttributes.Identity)
1420+
sum += getLengthOfStringPointer(event.DecisionTaskCompletedEventAttributes.BinaryChecksum)
14211421
}
14221422
case m.EventTypeDecisionTaskFailed:
14231423
if event.DecisionTaskFailedEventAttributes != nil {
@@ -1435,7 +1435,7 @@ func (weh *workflowExecutionEventHandlerImpl) estimateHistorySize(event *m.Histo
14351435
case m.EventTypeActivityTaskCompleted:
14361436
if event.ActivityTaskCompletedEventAttributes != nil {
14371437
sum += len(event.ActivityTaskCompletedEventAttributes.Result)
1438-
sum += len(*event.ActivityTaskCompletedEventAttributes.Identity)
1438+
sum += getLengthOfStringPointer(event.ActivityTaskCompletedEventAttributes.Identity)
14391439
}
14401440
case m.EventTypeActivityTaskFailed:
14411441
if event.ActivityTaskFailedEventAttributes != nil {
@@ -1486,7 +1486,7 @@ func (weh *workflowExecutionEventHandlerImpl) estimateHistorySize(event *m.Histo
14861486
case m.EventTypeChildWorkflowExecutionFailed:
14871487
if event.ChildWorkflowExecutionFailedEventAttributes != nil {
14881488
sum += len(event.ChildWorkflowExecutionFailedEventAttributes.Details)
1489-
sum += len(*event.ChildWorkflowExecutionFailedEventAttributes.Reason)
1489+
sum += getLengthOfStringPointer(event.ChildWorkflowExecutionFailedEventAttributes.Reason)
14901490
}
14911491
case m.EventTypeChildWorkflowExecutionCanceled:
14921492
if event.ChildWorkflowExecutionCanceledEventAttributes != nil {
@@ -1513,3 +1513,10 @@ func sizeOf(o map[string][]byte) int {
15131513
}
15141514
return sum
15151515
}
1516+
1517+
func getLengthOfStringPointer(s *string) int {
1518+
if s == nil {
1519+
return 0
1520+
}
1521+
return len(*s)
1522+
}

0 commit comments

Comments
 (0)