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=ac22e69bf7d4832bb1ed0ed681591e80a50d5b18 commit ac22e69bf7d4832bb1ed0ed681591e80a50d5b18 Author: Guillem Jover <[email protected]> AuthorDate: Tue Feb 4 04:36:38 2020 +0100 libdpkg: Use a varbuf to store the problem messages per parsedb context This both simplifies the code, gets rid of a static variable, and squashes a warning due to non-literal format strings. Warned-by: clang-10 -Wformat-nonliteral (from -Wformat=2) --- debian/changelog | 1 + lib/dpkg/parse.c | 2 ++ lib/dpkg/parsedump.h | 1 + lib/dpkg/parsehelp.c | 42 +++++++++++++++++++++--------------------- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/debian/changelog b/debian/changelog index 059914ed0..3241f6a57 100644 --- a/debian/changelog +++ b/debian/changelog @@ -200,6 +200,7 @@ dpkg (1.20.0) UNRELEASED; urgency=medium - libdpkg: Use a new DPKG_NULL macro that works in C and C++. - libdpkg: Use a new DPKG_STATIC_CAST macro that works in C and C++. - libdpkg: Move printing of errno into dpkg_error_set(). + - libdpkg: Use a varbuf to store the problem messages per parsedb context. * Build system: - Bump minimal Perl version to 5.24.1. - Add a serial versioning to the m4 files. diff --git a/lib/dpkg/parse.c b/lib/dpkg/parse.c index e7ae89faa..6c9c1ccbd 100644 --- a/lib/dpkg/parse.c +++ b/lib/dpkg/parse.c @@ -527,6 +527,7 @@ parsedb_new(const char *filename, int fd, enum parsedbflags flags) ps = m_malloc(sizeof(*ps)); ps->err = DPKG_ERROR_OBJECT; + ps->errmsg = VARBUF_OBJECT; ps->filename = filename; ps->type = parse_get_type(ps, flags); ps->flags = flags; @@ -754,6 +755,7 @@ parsedb_close(struct parsedb_state *ps) #endif } dpkg_error_destroy(&ps->err); + varbuf_destroy(&ps->errmsg); free(ps); } diff --git a/lib/dpkg/parsedump.h b/lib/dpkg/parsedump.h index ea29ff317..73331bca5 100644 --- a/lib/dpkg/parsedump.h +++ b/lib/dpkg/parsedump.h @@ -49,6 +49,7 @@ struct parsedb_state { enum parsedbtype type; enum parsedbflags flags; struct dpkg_error err; + struct varbuf errmsg; struct pkginfo *pkg; struct pkgbin *pkgbin; char *data; diff --git a/lib/dpkg/parsehelp.c b/lib/dpkg/parsehelp.c index 34247269e..5a2e2060a 100644 --- a/lib/dpkg/parsehelp.c +++ b/lib/dpkg/parsehelp.c @@ -36,35 +36,37 @@ #include <dpkg/error.h> #include <dpkg/parsedump.h> -static const char * -parse_error_msg(struct parsedb_state *ps, const char *fmt) +static DPKG_ATTR_VPRINTF(2) const char * +parse_error_msg(struct parsedb_state *ps, const char *fmt, va_list args) { - static char msg[1024]; - char filename[256]; + struct varbuf *vb = &ps->errmsg; - str_escape_fmt(filename, ps->filename, sizeof(filename)); + varbuf_reset(vb); - if (ps->pkg && ps->pkg->set->name) { - char pkgname[256]; + if (ps->pkg && ps->pkg->set->name) + varbuf_printf(vb, _("parsing file '%s' near line %d package '%s':\n "), + ps->filename, ps->lno, + pkgbin_name(ps->pkg, ps->pkgbin, pnaw_nonambig)); + else + varbuf_printf(vb, _("parsing file '%.255s' near line %d:\n "), + ps->filename, ps->lno); - str_escape_fmt(pkgname, pkgbin_name(ps->pkg, ps->pkgbin, pnaw_nonambig), - sizeof(pkgname)); - sprintf(msg, _("parsing file '%.255s' near line %d package '%.255s':\n" - " %.255s"), filename, ps->lno, pkgname, fmt); - } else - sprintf(msg, _("parsing file '%.255s' near line %d:\n" - " %.255s"), filename, ps->lno, fmt); + varbuf_vprintf(vb, fmt, args); - return msg; + return vb->buf; } void parse_error(struct parsedb_state *ps, const char *fmt, ...) { va_list args; + const char *str; va_start(args, fmt); - ohshitv(parse_error_msg(ps, fmt), args); + str = parse_error_msg(ps, fmt, args); + va_end(args); + + ohshit("%s", str); } void @@ -73,7 +75,7 @@ parse_warn(struct parsedb_state *ps, const char *fmt, ...) va_list args; va_start(args, fmt); - warningv(parse_error_msg(ps, fmt), args); + warning("%s", parse_error_msg(ps, fmt, args)); va_end(args); } @@ -81,18 +83,16 @@ void parse_problem(struct parsedb_state *ps, const char *fmt, ...) { va_list args; - char *str; + const char *str; va_start(args, fmt); - m_vasprintf(&str, parse_error_msg(ps, fmt), args); + str = parse_error_msg(ps, fmt, args); va_end(args); if (ps->err.type == DPKG_MSG_WARN) warning("%s: %s", str, ps->err.str); else ohshit("%s: %s", str, ps->err.str); - - free(str); } const struct fieldinfo * -- Dpkg.Org's dpkg

