Browse Source

libdpkg: Print correct integer parse error for short-only options

Some options do not provide a long name, we should handle that and
print an appropriate message, instead of passing NULL to printf.

Closes: #809174
Guillem Jover 10 years ago
parent
commit
36e272e27c
2 changed files with 8 additions and 2 deletions
  1. 2 0
      debian/changelog
  2. 6 2
      lib/dpkg/options.c

+ 2 - 0
debian/changelog

@@ -1,5 +1,7 @@
 dpkg (1.18.5) UNRELEASED; urgency=medium
 
+  * Print correct integer parse error for short-only command-line options.
+    This affects «dpkg-deb -z». Closes: #809174
   * Documentation:
     - Say value instead of option in deb-control(5).
     - Mark debian changelog format in bold in dpkg-parsechangelog(1).

+ 6 - 2
lib/dpkg/options.c

@@ -287,8 +287,12 @@ dpkg_options_parse_arg_int(const struct cmdinfo *cmd, const char *str)
 
   errno = 0;
   value = strtol(str, &end, 0);
-  if (str == end || *end || value < 0 || value > INT_MAX || errno != 0)
-    badusage(_("invalid integer for --%s: '%.250s'"), cmd->olong, str);
+  if (str == end || *end || value < 0 || value > INT_MAX || errno != 0) {
+    if (cmd->olong)
+      badusage(_("invalid integer for --%s: '%.250s'"), cmd->olong, str);
+    else
+      badusage(_("invalid integer for -%c: '%.250s'"), cmd->oshort, str);
+  }
 
   return value;
 }