From: Karel Zak Date: Wed, 22 Apr 2015 15:14:28 +0000 (+0200) Subject: libfdisk: fix scriptk parser to support alone signs X-Git-Tag: v2.27-rc1~248 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7c27ff2970e4149829e477521d4110171089982;p=thirdparty%2Futil-linux.git libfdisk: fix scriptk parser to support alone signs for example echo "- - - *" | sfdisk /dev/sda1 -N1 Signed-off-by: Karel Zak --- diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index 469c1d4c1a..4d0fd6e8d9 100644 --- a/libfdisk/src/script.c +++ b/libfdisk/src/script.c @@ -818,6 +818,8 @@ static struct fdisk_parttype *translate_type_shortcuts(struct fdisk_script *dp, #define TK_PLUS 1 #define TK_MINUS -1 +#define alone_sign(_sign, _p) (_sign && (*_p == '\0' || isblank(*_p))) + /* simple format: * , , , , ... */ @@ -848,18 +850,18 @@ static int parse_commas_line(struct fdisk_script *dp, char *s) p = (char *) skip_blank(p); item++; - DBG(SCRIPT, ul_debugobj(dp, " parsing item %d ('%s')", item, p)); - begin = p; - if (item != ITEM_BOOTABLE) { sign = *p == '-' ? TK_MINUS : *p == '+' ? TK_PLUS : 0; if (sign) p++; } + DBG(SCRIPT, ul_debugobj(dp, " parsing item %d ('%s')", item, p)); + begin = p; + switch (item) { case ITEM_START: - if (*p == ',' || *p == ';' || (sign && *p == '\0')) + if (*p == ',' || *p == ';' || alone_sign(sign, p)) fdisk_partition_start_follow_default(pa, 1); else { int pow = 0; @@ -877,7 +879,7 @@ static int parse_commas_line(struct fdisk_script *dp, char *s) } break; case ITEM_SIZE: - if (*p == ',' || *p == ';' || (sign && *p == '\0')) { + if (*p == ',' || *p == ';' || alone_sign(sign, p)) { fdisk_partition_end_follow_default(pa, 1); if (sign == TK_PLUS) /* alone '+' means use all possible space, elone '-' means nothing */ @@ -899,7 +901,7 @@ static int parse_commas_line(struct fdisk_script *dp, char *s) } break; case ITEM_TYPE: - if (*p == ',' || *p == ';' || (sign && *p == '\0')) + if (*p == ',' || *p == ';' || alone_sign(sign, p)) break; /* use default type */ rc = next_string(&p, &str);