libupkg: Make decodeindex test accept an empty string.
authorNick Bowler <nbowler@draconx.ca>
Fri, 11 May 2012 23:24:01 +0000 (19:24 -0400)
committerNick Bowler <nbowler@draconx.ca>
Fri, 11 May 2012 23:24:01 +0000 (19:24 -0400)
This test app should not reject empty input outright, because it should
be properly rejected by the function under test.

test/decodeindex.c

index bbe15f4ed86acfd99946453ef28d1827b6a4756b..d3f099a6824ac66ec4efe6f1771995c9a52cc01d 100644 (file)
@@ -86,6 +86,12 @@ static void print_version(void)
 static void print_bytes(FILE *f, int indent, void *buf, size_t n)
 {
        fprintf(f, "%*s", indent, "");
+
+       if (n == 0) {
+               printf("(empty)\n");
+               return;
+       }
+
        for (size_t i = 0; i < n; i++)
                fprintf(f, "%*s%.2hhx", i != 0, "", ((unsigned char *)buf)[i]);
        putc('\n', f);
@@ -103,9 +109,6 @@ static int print_index(const char *hex)
                fprintf(stderr, "%s: invalid hex sequence: %s\n",
                                progname, hex);
                goto out;
-       } else if (n == 0) {
-               fprintf(stderr, "%s: empty argument\n", progname);
-               goto out;
        } else if (n > sizeof buf) {
                fprintf(stderr, "%s: hex sequence too long: %s\n",
                                progname, hex);