This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=5e3ffab92fcc099000ab6308eba3140d20796cfc

commit 5e3ffab92fcc099000ab6308eba3140d20796cfc
Author: Guillem Jover <[email protected]>
AuthorDate: Wed Jan 29 00:20:41 2020 +0100

    u-a: Move error context setup before calling setjmp()
    
    This is a cppcheck false-positive, but by rearranging the code we can
    avoid it, and it makes it somewhat more clear anyway.
    
    This was causing lots of fuzzying when the line numbers were getting
    changed.
    
    Warned-by: cppcheck
---
 debian/changelog            |  2 ++
 t/cppcheck/cppcheck.supp    |  3 ---
 utils/update-alternatives.c | 15 ++++++++-------
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 349d869b4..876d80782 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -161,6 +161,8 @@ dpkg (1.20.0) UNRELEASED; urgency=medium
       constness of a variable.
     - Dpkg::Dist::Files: Document the two filename pattern formats.
     - update-alternatives: Remove redundant condition in argument parser.
+    - update-alternatives: Move error context setup before calling setjmp(),
+      so that cppcheck stops being confused.
   * Build system:
     - Bump minimal Perl version to 5.24.1.
     - Add a serial versioning to the m4 files.
diff --git a/t/cppcheck/cppcheck.supp b/t/cppcheck/cppcheck.supp
index 36202224f..880cf79b3 100644
--- a/t/cppcheck/cppcheck.supp
+++ b/t/cppcheck/cppcheck.supp
@@ -50,9 +50,6 @@ nullPointerArithmeticRedundantCheck:lib/dpkg/pkg-format.c:82
 // BUG: False positive, does not understand setjmp-style error handling.
 redundantAssignment:lib/compat/selinux.c:73
 nullPointerRedundantCheck:utils/update-alternatives.c:1193
-uninitStructMember:utils/update-alternatives.c:1340
-uninitStructMember:utils/update-alternatives.c:1341
-uninitStructMember:utils/update-alternatives.c:1342
 
 // BUG: False positive, does not understand ohshit(), ohshite() and
 //      bad_format as error terminators.
diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c
index 8339e41f1..c01bd6549 100644
--- a/utils/update-alternatives.c
+++ b/utils/update-alternatives.c
@@ -1336,13 +1336,6 @@ alternative_load(struct alternative *a, enum altdb_flags 
flags)
        char *master_link;
 
        /* Initialize parse context */
-       if (setjmp(ctx.on_error)) {
-               if (ctx.fh)
-                       fclose(ctx.fh);
-               free(ctx.filename);
-               alternative_reset(a);
-               return false;
-       }
        ctx.modified = false;
        ctx.flags = flags;
        if (flags & ALTDB_LAX_PARSER)
@@ -1360,6 +1353,14 @@ alternative_load(struct alternative *a, enum altdb_flags 
flags)
                syserr(_("unable to open file '%s'"), ctx.filename);
        }
 
+       if (setjmp(ctx.on_error)) {
+               if (ctx.fh)
+                       fclose(ctx.fh);
+               free(ctx.filename);
+               alternative_reset(a);
+               return false;
+       }
+
        /* Verify the alternative is not empty. */
        if (fstat(fileno(ctx.fh), &st) == -1)
                syserr(_("cannot stat file '%s'"), ctx.filename);

-- 
Dpkg.Org's dpkg

Reply via email to