diff --git a/src/detect-engine-address.c b/src/detect-engine-address.c index 6fb7f25738..8245c9b807 100644 --- a/src/detect-engine-address.c +++ b/src/detect-engine-address.c @@ -1140,14 +1140,12 @@ int DetectAddressMergeNot(DetectAddressHead *gh, DetectAddressHead *ghn) r = DetectAddressCmp(ag, ag2); /* XXX more ??? */ if (r == ADDRESS_EQ || r == ADDRESS_EB) { - if (ag2->prev == NULL) - gh->ipv4_head = ag2->next; - else + if (ag2->prev != NULL) ag2->prev->next = ag2->next; - if (ag2->next != NULL) ag2->next->prev = ag2->prev; - + if (gh->ipv4_head == ag2) + gh->ipv4_head = ag2->next; /* store the next ptr and remove the group */ DetectAddress *next_ag2 = ag2->next; DetectAddressFree(ag2); @@ -1168,14 +1166,12 @@ int DetectAddressMergeNot(DetectAddressHead *gh, DetectAddressHead *ghn) for (ag2 = gh->ipv6_head; ag2 != NULL; ) { r = DetectAddressCmp(ag, ag2); if (r == ADDRESS_EQ || r == ADDRESS_EB) { /* XXX more ??? */ - if (ag2->prev == NULL) - gh->ipv6_head = ag2->next; - else + if (ag2->prev != NULL) ag2->prev->next = ag2->next; - if (ag2->next != NULL) ag2->next->prev = ag2->prev; - + if (gh->ipv6_head == ag2) + gh->ipv6_head = ag2->next; /* store the next ptr and remove the group */ DetectAddress *next_ag2 = ag2->next; DetectAddressFree(ag2); diff --git a/src/detect-engine-port.c b/src/detect-engine-port.c index fe73395151..5129a6b92b 100644 --- a/src/detect-engine-port.c +++ b/src/detect-engine-port.c @@ -1137,15 +1137,12 @@ static int DetectPortParseMergeNotPorts(const DetectEngineCtx *de_ctx, r = DetectPortCmp(ag, ag2); if (r == PORT_EQ || r == PORT_EB) { /* XXX more ??? */ - if (ag2->prev == NULL) { - *head = ag2->next; - } else { + if (ag2->prev != NULL) ag2->prev->next = ag2->next; - } - - if (ag2->next != NULL) { + if (ag2->next != NULL) ag2->next->prev = ag2->prev; - } + if (*head == ag2) + *head = ag2->next; /** store the next ptr and remove the group */ DetectPort *next_ag2 = ag2->next; DetectPortFree(de_ctx,ag2);