Skip to content

Commit

Permalink
Safer assert
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-gr committed Nov 13, 2024
1 parent d049b71 commit db5a57d
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions winlogbeat/sys/wineventlog/publisher_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,10 @@ func NewMetadataKeyword(publisherMetadataHandle EvtHandle, arrayHandle EvtObject
if err != nil {
return nil, err
}
messageID := v.(uint32)

// The value is -1 if the keyword did not specify a message attribute.
messageID, ok := v.(uint32)
var message string
if int32(messageID) != -1 {
// The value is -1 if the keyword did not specify a message attribute.
if ok {
message, err = evtFormatMessage(publisherMetadataHandle, NilHandle, messageID, nil, EvtFormatMessageId)
if err != nil {
return nil, err
Expand Down Expand Up @@ -271,11 +270,10 @@ func NewMetadataOpcode(publisherMetadataHandle EvtHandle, arrayHandle EvtObjectA
if err != nil {
return nil, err
}
messageID := v.(uint32)

messageID, ok := v.(uint32)
// The value is -1 if the opcode did not specify a message attribute.
var message string
if int32(messageID) != -1 {
if ok {
message, err = evtFormatMessage(publisherMetadataHandle, NilHandle, messageID, nil, EvtFormatMessageId)
if err != nil {
return nil, err
Expand Down Expand Up @@ -344,11 +342,10 @@ func NewMetadataLevel(publisherMetadataHandle EvtHandle, arrayHandle EvtObjectAr
if err != nil {
return nil, err
}
messageID := v.(uint32)

messageID, ok := v.(uint32)
// The value is -1 if the level did not specify a message attribute.
var message string
if int32(messageID) != -1 {
if ok {
message, err = evtFormatMessage(publisherMetadataHandle, NilHandle, messageID, nil, EvtFormatMessageId)
if err != nil {
return nil, err
Expand Down Expand Up @@ -418,11 +415,10 @@ func NewMetadataTask(publisherMetadataHandle EvtHandle, arrayHandle EvtObjectArr
if err != nil {
return nil, err
}
messageID := v.(uint32)

messageID, ok := v.(uint32)
// The value is -1 if the task did not specify a message attribute.
var message string
if int32(messageID) != -1 {
if ok {
message, err = evtFormatMessage(publisherMetadataHandle, NilHandle, messageID, nil, EvtFormatMessageId)
if err != nil {
return nil, err
Expand Down Expand Up @@ -499,11 +495,10 @@ func NewMetadataChannel(publisherMetadataHandle EvtHandle, arrayHandle EvtObject
if err != nil {
return nil, err
}
messageID := v.(uint32)

// The value is -1 if the task did not specify a message attribute.
messageID, ok := v.(uint32)
// The value is -1 if the channel did not specify a message attribute.
var message string
if int32(messageID) != -1 {
if ok {
message, err = evtFormatMessage(publisherMetadataHandle, NilHandle, messageID, nil, EvtFormatMessageId)
if err != nil {
return nil, err
Expand Down

0 comments on commit db5a57d

Please sign in to comment.