bgpd: fix return NULL in bool function ecommunity_node_target_match - #22273
Conversation
ecommunity_node_target_match() is declared as returning bool, but the early-exit path for empty or missing ecommunity uses 'return NULL'. NULL is a pointer constant ((void*)0), not a boolean value. Returning a pointer type from a bool function relies on an implicit pointer-to- integer conversion, which is undefined behavior per the C standard (C11 6.8.6.4). While most compilers implicitly convert NULL to false (0), this is not guaranteed and produces warnings under -Wpedantic or -Wint-conversion, which can break builds with -Werror enabled. The function already declares 'bool match = false' and returns match at the end, so the intent of the early-exit is clearly to return false when the ecommunity is empty or NULL. Change 'return NULL' to 'return false' to match the function's return type and eliminate the undefined behavior. Signed-off-by: guozhongfeng.gzf <guozhongfeng.gzf@alibaba-inc.com>
Greptile SummaryThis PR corrects an improper
Confidence Score: 5/5Safe to merge β the one-line change corrects a type mismatch that had no observable behavioral difference on mainstream compilers but was technically non-conforming. The change is a trivial, well-scoped correction: the early return in No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[ecommunity_node_target_match called] --> B{ecom is NULL or ecom->size == 0?}
B -- "Yes (before)" --> C["return NULL β (implicit pointer-to-int)"]
B -- "Yes (after)" --> D["return false β
(correct bool)"]
B -- No --> E[Iterate over ecommunity entries]
E --> F{type == ENCODE_IP && sub_type == NODE_TARGET?}
F -- Yes --> G{IPV4_ADDR_SAME match?}
G -- Yes --> H[match = true]
G -- No --> I[continue]
F -- No --> I
H --> J[return match]
I --> J
Reviews (1): Last reviewed commit: "bgpd: fix return NULL in bool function e..." | Re-trigger Greptile |
|
@Mergifyio backport stable/10.6 stable/10.5 stable/10.4 stable/10.3 |
β Backports have been createdDetails
|
bgpd: fix return NULL in bool function ecommunity_node_target_match (backport #22273)
bgpd: fix return NULL in bool function ecommunity_node_target_match (backport #22273)
bgpd: fix return NULL in bool function ecommunity_node_target_match (backport #22273)
bgpd: fix return NULL in bool function ecommunity_node_target_match (backport #22273)
ecommunity_node_target_match() is declared as returning bool, but the early-exit path for empty or missing ecommunity uses 'return NULL'.
NULL is a pointer constant ((void*)0), not a boolean value. Returning a pointer type from a bool function relies on an implicit pointer-to- integer conversion, which is undefined behavior per the C standard (C11 6.8.6.4). While most compilers implicitly convert NULL to false (0), this is not guaranteed and produces warnings under -Wpedantic or -Wint-conversion, which can break builds with -Werror enabled.
The function already declares 'bool match = false' and returns match at the end, so the intent of the early-exit is clearly to return false when the ecommunity is empty or NULL.
Change 'return NULL' to 'return false' to match the function's return type and eliminate the undefined behavior.