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

guillem pushed a commit to branch main
in repository dpkg.

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

commit e11fb5a91eb89c7ccbf458467798dfc4ad014169
Author: Guillem Jover <[email protected]>
AuthorDate: Sun Nov 5 01:26:40 2023 +0100

    u-a: Wrap the bad_format() function pointer call into a new function
    
    This simplifies somewhat the callers which do not need to use ctx to
    access the parse error function and pass it as an argument. And makes
    it possible for cppcheck to understand that this is a non-returning
    function, which it seems to be unable to do with a function pointer.
---
 utils/update-alternatives.c | 72 ++++++++++++++++++++++++++-------------------
 1 file changed, 41 insertions(+), 31 deletions(-)

diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c
index 30cf153bb..7d21a4d47 100644
--- a/utils/update-alternatives.c
+++ b/utils/update-alternatives.c
@@ -1264,8 +1264,8 @@ struct altdb_context {
        char *filename;
        enum altdb_flags flags;
        bool modified;
-       void LIBCOMPAT_ATTR_NORET LIBCOMPAT_ATTR_PRINTF(2)
-            (*bad_format)(struct altdb_context *, const char *format, ...);
+       void LIBCOMPAT_ATTR_NORET
+            (*bad_format)(struct altdb_context *, const char *msg);
        jmp_buf on_error;
 };
 
@@ -1277,6 +1277,23 @@ altdb_context_free(struct altdb_context *ctx)
        free(ctx->filename);
 }
 
+static void LIBCOMPAT_ATTR_NORET LIBCOMPAT_ATTR_PRINTF(2)
+altdb_bad_format(struct altdb_context *ctx, const char *format, ...)
+{
+       va_list args;
+       char *msg;
+
+       va_start(args, format);
+       msg = xvasprintf(format, args);
+       va_end(args);
+
+       ctx->bad_format(ctx, msg);
+
+       /* This cannot happen, but just to make sure the bad_format() function
+        * pointer is well implemented. */
+       error("(internal) non returning bad-format function returned");
+}
+
 static int
 altdb_filter_namelist(const struct dirent *entry)
 {
@@ -1337,37 +1354,30 @@ altdb_get_line(struct altdb_context *ctx, const char 
*name)
                        continue;
                }
                if (feof(ctx->fh))
-                       ctx->bad_format(ctx, _("unexpected end of file while 
trying "
-                                              "to read %s"), name);
-               ctx->bad_format(ctx, _("while reading %s: %s"),
-                               name, strerror(errno));
+                       altdb_bad_format(ctx, _("unexpected end of file while 
trying "
+                                               "to read %s"), name);
+               altdb_bad_format(ctx, _("while reading %s: %s"),
+                                name, strerror(errno));
        }
 
        len = strlen(buf);
        if (len == 0 || buf[len - 1] != '\n') {
-               ctx->bad_format(ctx, _("line not terminated while trying "
-                                      "to read %s"), name);
+               altdb_bad_format(ctx, _("line not terminated while trying "
+                                       "to read %s"), name);
        }
        line[len - 1] = '\0';
 
        return buf;
 }
 
-static void LIBCOMPAT_ATTR_NORET LIBCOMPAT_ATTR_PRINTF(2)
-altdb_parse_error(struct altdb_context *ctx, const char *format, ...)
+static void LIBCOMPAT_ATTR_NORET
+altdb_parse_error(struct altdb_context *ctx, const char *msg)
 {
-       char *msg;
-       va_list args;
-
-       va_start(args, format);
-       msg = xvasprintf(format, args);
-       va_end(args);
-
        error(_("%s corrupt: %s"), ctx->filename, msg);
 }
 
-static void LIBCOMPAT_ATTR_NORET LIBCOMPAT_ATTR_PRINTF(2)
-altdb_parse_stop(struct altdb_context *ctx, const char *format, ...)
+static void LIBCOMPAT_ATTR_NORET
+altdb_parse_stop(struct altdb_context *ctx, const char *msg)
 {
        longjmp(ctx->on_error, 1);
 }
@@ -1397,22 +1407,22 @@ alternative_parse_slave(struct alternative *a, struct 
altdb_context *ctx)
        sl = alternative_get_slave(a, name);
        if (sl) {
                free(name);
-               ctx->bad_format(ctx, _("duplicate slave name %s"), sl->name);
+               altdb_bad_format(ctx, _("duplicate slave name %s"), sl->name);
        }
 
        linkname = altdb_get_line(ctx, _("slave link"));
        if (strcmp(linkname, a->master_link) == 0) {
                free(linkname);
                free(name);
-               ctx->bad_format(ctx, _("slave link same as main link %s"),
-                               a->master_link);
+               altdb_bad_format(ctx, _("slave link same as main link %s"),
+                                a->master_link);
        }
        for (sl = a->slaves; sl; sl = sl->next) {
                if (strcmp(linkname, sl->link) == 0) {
                        free(linkname);
                        free(name);
-                       ctx->bad_format(ctx, _("duplicate slave link %s"),
-                                       sl->link);
+                       altdb_bad_format(ctx, _("duplicate slave link %s"),
+                                        sl->link);
                }
        }
 
@@ -1438,7 +1448,7 @@ alternative_parse_fileset(struct alternative *a, struct 
altdb_context *ctx)
 
        fs = alternative_get_fileset(a, master_file);
        if (fs)
-               ctx->bad_format(ctx, _("duplicate path %s"), master_file);
+               altdb_bad_format(ctx, _("duplicate path %s"), master_file);
 
        if (fsys_pathname_is_missing(master_file)) {
                char *junk;
@@ -1464,12 +1474,12 @@ alternative_parse_fileset(struct alternative *a, struct 
altdb_context *ctx)
                prio = strtol(prio_str, &prio_end, 10);
                /* XXX: Leak master_file/prio_str on non-fatal error */
                if (prio_str == prio_end || *prio_end != '\0')
-                       ctx->bad_format(ctx, _("priority of %s: %s"),
-                                       master_file, prio_str);
+                       altdb_bad_format(ctx, _("priority of %s: %s"),
+                                        master_file, prio_str);
                if (prio < INT_MIN || prio > INT_MAX || errno == ERANGE)
-                       ctx->bad_format(ctx,
-                                       _("priority of %s is out of range: %s"),
-                                       master_file, prio_str);
+                       altdb_bad_format(ctx,
+                                        _("priority of %s is out of range: 
%s"),
+                                        master_file, prio_str);
                free(prio_str);
 
                fs = fileset_new(master_file, prio);
@@ -1532,7 +1542,7 @@ alternative_load(struct alternative *a, enum altdb_flags 
flags)
        alternative_reset(a);
        status = altdb_get_line(&ctx, _("status"));
        if (strcmp(status, "auto") != 0 && strcmp(status, "manual") != 0)
-               ctx.bad_format(&ctx, _("invalid status"));
+               altdb_bad_format(&ctx, _("invalid status"));
        alternative_set_status(a, (strcmp(status, "auto") == 0) ?
                               ALT_ST_AUTO : ALT_ST_MANUAL);
        free(status);

-- 
Dpkg.Org's dpkg

Reply via email to