diff mbox series

[ovs-dev,PATCHv2,2/2] ovn-sbctl: Fix possible null pointer to qsort.

Message ID 1509496191-28209-2-git-send-email-u9012063@gmail.com
State Accepted
Headers show
Series [ovs-dev,PATCHv2,1/2] ofproto-dpif-xlate: Fix bad memory free. | expand

Commit Message

William Tu Nov. 1, 2017, 12:29 a.m. UTC
Clang reports possible null pointer 'lflows' passed to qsort.
This is due to the checker unable to make sure whether 'lflows'
gets malloc or not in the previous loop.  Fix it by checking the
'n_flows' before calling qsort.

Signed-off-by: William Tu <u9012063@gmail.com>
---
 ovn/utilities/ovn-sbctl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Ben Pfaff Nov. 1, 2017, 8:08 p.m. UTC | #1
On Tue, Oct 31, 2017 at 05:29:51PM -0700, William Tu wrote:
> Clang reports possible null pointer 'lflows' passed to qsort.
> This is due to the checker unable to make sure whether 'lflows'
> gets malloc or not in the previous loop.  Fix it by checking the
> 'n_flows' before calling qsort.
> 
> Signed-off-by: William Tu <u9012063@gmail.com>

Thanks for the patches!  I applied both of these to master.
diff mbox series

Patch

diff --git a/ovn/utilities/ovn-sbctl.c b/ovn/utilities/ovn-sbctl.c
index c5ec4e6eaf24..6f3743b55632 100644
--- a/ovn/utilities/ovn-sbctl.c
+++ b/ovn/utilities/ovn-sbctl.c
@@ -860,7 +860,10 @@  cmd_lflow_list(struct ctl_context *ctx)
         lflows[n_flows] = lflow;
         n_flows++;
     }
-    qsort(lflows, n_flows, sizeof *lflows, lflow_cmp);
+
+    if (n_flows) {
+        qsort(lflows, n_flows, sizeof *lflows, lflow_cmp);
+    }
 
     bool print_uuid = shash_find(&ctx->options, "--uuid") != NULL;