From 1002e3fe1ddb1d95c838197dc802c3b1ba094bd3 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 9 Nov 2014 09:33:48 +0100 Subject: Fix warnings: fold.c: get_foldtext(): Np dereference: FP. Problem : Dereference of null pointer @ 1701. Diagnostic : False positive. Rationale : Comparison `last_wp != wp` just after initializing `last_wp` to NULL makes the compiler think `wp` can be null. Error appears then on codepath assuming comparison is false (i.e. `wp` is null). Resolution : Change order of OR clauses. That seems not to give motives for the analyzer to check the `wp` null path and removes the warning. But potential null dereference is still there, so we add the nonnull annotation to `wp` parameter. --- src/nvim/fold.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 95f1e054b9..6014dbfd15 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -22,6 +22,7 @@ #include "nvim/diff.h" #include "nvim/eval.h" #include "nvim/ex_docmd.h" +#include "nvim/func_attr.h" #include "nvim/indent.h" #include "nvim/mark.h" #include "nvim/memline.h" @@ -1680,7 +1681,9 @@ static void foldDelMarker(linenr_T lnum, char_u *marker, int markerlen) * When 'foldtext' isn't set puts the result in "buf[51]". Otherwise the * result is in allocated memory. */ -char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T *foldinfo, char_u *buf) +char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, + foldinfo_T *foldinfo, char_u *buf) + FUNC_ATTR_NONNULL_ARG(1) { char_u *text = NULL; /* an error occurred when evaluating 'fdt' setting */ @@ -1689,8 +1692,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T *foldi static win_T *last_wp = NULL; static linenr_T last_lnum = 0; - if (last_wp != wp || last_wp == NULL - || last_lnum > lnum || last_lnum == 0) + if (last_wp == NULL || last_wp != wp || last_lnum > lnum || last_lnum == 0) /* window changed, try evaluating foldtext setting once again */ got_fdt_error = FALSE; -- cgit