summaryrefslogtreecommitdiff
path: root/conf/cf-lex.l
diff options
context:
space:
mode:
Diffstat (limited to 'conf/cf-lex.l')
-rw-r--r--conf/cf-lex.l46
1 files changed, 15 insertions, 31 deletions
diff --git a/conf/cf-lex.l b/conf/cf-lex.l
index 9025a84d..965e1e3f 100644
--- a/conf/cf-lex.l
+++ b/conf/cf-lex.l
@@ -256,38 +256,22 @@ WHITE [ \t]
}
({XIGIT}{2}){16,}|{XIGIT}{2}(:{XIGIT}{2}){15,}|hex:({XIGIT}{2}(:?{XIGIT}{2})*)? {
- char *s, *sb = yytext;
- size_t len = 0, i;
- struct bytestring *bytes;
- byte *b;
-
- /* skip 'hex:' prefix */
- if (sb[0] == 'h' && sb[1] == 'e' && sb[2] == 'x' && sb[3] == ':')
- sb += 4;
-
- s = sb;
- while (*s) {
- len++;
- s += 2;
- if (*s == ':')
- s++;
- }
- bytes = cfg_allocz(sizeof(*bytes) + len);
+ char *s = yytext;
+ struct bytestring *bs;
- bytes->length = len;
- b = &bytes->data[0];
- s = sb;
- errno = 0;
- for (i = 0; i < len; i++) {
- *b = bstrtobyte16(s);
- if (errno == ERANGE)
- cf_error("Invalid hex string");
- b++;
- s += 2;
- if (*s == ':')
- s++;
- }
- cf_lval.bs = bytes;
+ /* Skip 'hex:' prefix */
+ if (s[0] == 'h' && s[1] == 'e' && s[2] == 'x' && s[3] == ':')
+ s += 4;
+
+ int len = bstrhextobin(s, NULL);
+ if (len < 0)
+ cf_error("Invalid hex string");
+
+ bs = cfg_allocz(sizeof(struct bytestring) + len);
+ bs->length = bstrhextobin(s, bs->data);
+ ASSERT(bs->length == len);
+
+ cf_lval.bs = bs;
return BYTESTRING;
}