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=37b8a0ea1ab1bd96dd7a4c8c1a90ef76a6a0802b commit 37b8a0ea1ab1bd96dd7a4c8c1a90ef76a6a0802b (HEAD -> master) Author: Guillem Jover <[email protected]> AuthorDate: Thu Jan 16 04:30:20 2020 +0100 libdpkg: Fix format string to be a string literal This also removes an intermediate string formatting. Warned-by: gcc-10, gcc -Wformat=2 --- debian/changelog | 2 ++ lib/dpkg/pkg-format.c | 25 ++++++++----------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/debian/changelog b/debian/changelog index 6189967ec..359440af9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -115,6 +115,8 @@ dpkg (1.20.0) UNRELEASED; urgency=medium warning. - libdpkg: Only use varbuf_printf() in pkg_format_show() when necessary. This should speed up «dpkg-query --show» formatting. + - libdpkg: Fix package format string to be a string literal. + This suppresses a gcc warning. * Build system: - Bump minimal Perl version to 5.24.1. - Add a serial versioning to the m4 files. diff --git a/lib/dpkg/pkg-format.c b/lib/dpkg/pkg-format.c index d600a947f..e9e1b0ee8 100644 --- a/lib/dpkg/pkg-format.c +++ b/lib/dpkg/pkg-format.c @@ -51,8 +51,7 @@ enum pkg_format_type { struct pkg_format_node { struct pkg_format_node *next; enum pkg_format_type type; - size_t width; - int pad; + int width; char *data; }; @@ -67,7 +66,6 @@ pkg_format_node_new(void) buf->next = NULL; buf->data = NULL; buf->width = 0; - buf->pad = 0; return buf; } @@ -99,11 +97,7 @@ parsefield(struct pkg_format_node *node, const char *fmt, const char *fmtend, return false; } - if (w < 0) { - node->pad = 1; - node->width = (size_t)-w; - } else - node->width = (size_t)w; + node->width = w; len = ws - fmt; } @@ -394,13 +388,8 @@ pkg_format_item(struct varbuf *vb, { if (node->width == 0) varbuf_add_str(vb, str); - else { - char fmt[16]; - - snprintf(fmt, sizeof(fmt), "%%%s%zus", - ((node->pad) ? "-" : ""), node->width); - varbuf_printf(vb, fmt, str); - } + else + varbuf_printf(vb, "%*s", node->width, str); } void @@ -443,8 +432,10 @@ pkg_format_show(const struct pkg_format_node *head, if (ok) { size_t len = fb.used; - if ((node->width > 0) && (len > node->width)) - len = node->width; + size_t width = abs(node->width); + + if ((width != 0) && (len > width)) + len = width; varbuf_add_buf(&vb, fb.buf, len); } -- Dpkg.Org's dpkg

