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=191071aa4d06dda6db6046317eade85bf7d87cc4 commit 191071aa4d06dda6db6046317eade85bf7d87cc4 Author: Guillem Jover <[email protected]> AuthorDate: Sun Nov 27 02:17:41 2022 +0100 libdpkg: Refactor debug_parse_mask() We will use this function to parse both the argument from the CLI option, and a new environment variable. --- lib/dpkg/debug.c | 24 ++++++++++++++++++++++++ lib/dpkg/debug.h | 1 + lib/dpkg/libdpkg.map | 1 + src/main/main.c | 8 ++------ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/dpkg/debug.c b/lib/dpkg/debug.c index ddbd394c9..efd8c70a4 100644 --- a/lib/dpkg/debug.c +++ b/lib/dpkg/debug.c @@ -22,7 +22,9 @@ #include <config.h> #include <compat.h> +#include <errno.h> #include <stdarg.h> +#include <stdlib.h> #include <stdio.h> #include <dpkg/dpkg.h> @@ -59,6 +61,28 @@ debug_set_mask(int mask) debug_output = stderr; } +/** + * Parse the debugging mask. + * + * The mask is parsed from the specified string and sets the global debugging + * mask. If there is any error while parsing a negative number is returned. + */ +int +debug_parse_mask(const char *str) +{ + char *endp; + long mask; + + errno = 0; + mask = strtol(str, &endp, 8); + if (str == endp || *endp || mask < 0 || errno == ERANGE) + return -1; + + debug_set_mask(mask); + + return mask; +} + /** * Check if a debugging flag is currently set on the debugging mask. */ diff --git a/lib/dpkg/debug.h b/lib/dpkg/debug.h index 3f98ac78a..bb08a1543 100644 --- a/lib/dpkg/debug.h +++ b/lib/dpkg/debug.h @@ -56,6 +56,7 @@ enum debugflags { void debug_set_output(FILE *output, const char *filename); void debug_set_mask(int mask); +int debug_parse_mask(const char *str); bool debug_has_flag(int flag); void debug(int flag, const char *fmt, ...) DPKG_ATTR_PRINTF(2); diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map index 74edd20b5..a525f4fee 100644 --- a/lib/dpkg/libdpkg.map +++ b/lib/dpkg/libdpkg.map @@ -68,6 +68,7 @@ LIBDPKG_PRIVATE { debug_set_output; debug_set_mask; + debug_parse_mask; debug_has_flag; debug; diff --git a/src/main/main.c b/src/main/main.c index 48082efc0..a1b3c3f72 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -230,7 +230,6 @@ static const struct debuginfo { static void set_debug(const struct cmdinfo *cpi, const char *value) { - char *endp; long mask; const struct debuginfo *dip; @@ -250,12 +249,9 @@ set_debug(const struct cmdinfo *cpi, const char *value) exit(0); } - errno = 0; - mask = strtol(value, &endp, 8); - if (value == endp || *endp || mask < 0 || errno == ERANGE) + mask = debug_parse_mask(value); + if (mask < 0) badusage(_("--%s requires a positive octal argument"), cpi->olong); - - debug_set_mask(mask); } static void -- Dpkg.Org's dpkg

