libyang REFACTOR avoid constant literals
Improve readability of the code.
Includes also unification of "no break in the case" comment to "fall
through".
diff --git a/src/common.h b/src/common.h
index 28959d9..122787c 100644
--- a/src/common.h
+++ b/src/common.h
@@ -333,6 +333,29 @@
#define ly_strlen(STR) (STR ? strlen(STR) : 0)
/**
+ * @brief Compile-time strlen() for string contants.
+ *
+ * Use to avoid magic numbers usage
+ */
+#define ly_strlen_const(STR) (sizeof STR - 1)
+
+#define ly_sizeofarray(ARRAY) (sizeof ARRAY / sizeof *ARRAY)
+
+/*
+ * Numerical bases for use in functions like strtoll() instead of magic numbers
+ */
+#define LY_BASE_DEC 10 /**< Decimal numeral base */
+#define LY_BASE_OCT 8 /**< Octal numeral base */
+#define LY_BASE_HEX 16 /**< Hexadecimal numeral base */
+
+/**
+ * Maximal length of (needed storage for) a number encoded as a string.
+ *
+ * Applies not only for standard numbers, but also for YANG's decimal64.
+ */
+#define LY_NUMBER_MAXLEN 22
+
+/**
* @brief Get UTF8 code point of the next character in the input string.
*
* @param[in,out] input Input string to process, updated according to the processed/read data.
diff --git a/src/context.c b/src/context.c
index 981ed42..f13da5f 100644
--- a/src/context.c
+++ b/src/context.c
@@ -117,15 +117,17 @@
API const char * const *
ly_ctx_get_searchdirs(const struct ly_ctx *ctx)
{
+#define LY_CTX_SEARCHDIRS_SIZE_STEP 8
void **new;
LY_CHECK_ARG_RET(ctx, ctx, NULL);
if (ctx->search_paths.count == ctx->search_paths.size) {
/* not enough space for terminating NULL byte */
- new = realloc(((struct ly_ctx *)ctx)->search_paths.objs, (ctx->search_paths.size + 8) * sizeof *ctx->search_paths.objs);
+ new = realloc(((struct ly_ctx *)ctx)->search_paths.objs,
+ (ctx->search_paths.size + LY_CTX_SEARCHDIRS_SIZE_STEP) * sizeof *ctx->search_paths.objs);
LY_CHECK_ERR_RET(!new, LOGMEM(NULL), NULL);
- ((struct ly_ctx *)ctx)->search_paths.size += 8;
+ ((struct ly_ctx *)ctx)->search_paths.size += LY_CTX_SEARCHDIRS_SIZE_STEP;
((struct ly_ctx *)ctx)->search_paths.objs = new;
}
/* set terminating NULL byte to the strings list */
@@ -704,7 +706,7 @@
uint32_t i;
ly_bool bis = 0;
int r;
- char id[8], *str;
+ char *str;
const struct lys_module *mod;
struct lyd_node *root = NULL, *root_bis = NULL, *cont, *set_bis = NULL;
@@ -809,18 +811,21 @@
}
/* IDs */
- sprintf(id, "%u", ctx->module_set_id);
- LY_CHECK_GOTO(ret = lyd_new_term(root, NULL, "module-set-id", id, 0, NULL), error);
+ r = asprintf(&str, "%u", ctx->module_set_id);
+ LY_CHECK_ERR_GOTO(r == -1, LOGMEM(ctx); ret = LY_EMEM, error);
+ ret = lyd_new_term(root, NULL, "module-set-id", str, 0, NULL);
+ LY_CHECK_ERR_GOTO(ret, free(str), error);
if (bis) {
/* create one complete schema */
- LY_CHECK_GOTO(ret = lyd_new_list(root_bis, NULL, "schema", 0, &cont, "complete"), error);
+ LY_CHECK_ERR_GOTO(ret = lyd_new_list(root_bis, NULL, "schema", 0, &cont, "complete"), free(str), error);
- LY_CHECK_GOTO(ret = lyd_new_term(cont, NULL, "module-set", "complete", 0, NULL), error);
+ LY_CHECK_ERR_GOTO(ret = lyd_new_term(cont, NULL, "module-set", "complete", 0, NULL), free(str), error);
/* content-id */
- LY_CHECK_GOTO(ret = lyd_new_term(root_bis, NULL, "content-id", id, 0, NULL), error);
+ LY_CHECK_ERR_GOTO(ret = lyd_new_term(root_bis, NULL, "content-id", str, 0, NULL), free(str), error);
}
+ free(str);
if (root_bis) {
if (lyd_insert_sibling(root, root_bis, &root)) {
diff --git a/src/diff.c b/src/diff.c
index 347ebf8..f0dcbda 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -1300,7 +1300,7 @@
case LYD_DIFF_OP_REPLACE:
/* similar to none operation but also remove the redundant attribute */
lyd_diff_del_meta(diff_match, "orig-value");
- /* fallthrough */
+ /* fall through */
case LYD_DIFF_OP_NONE:
/* it was not modified, but should be deleted -> set DELETE operation */
LY_CHECK_RET(lyd_diff_change_op(diff_match, LYD_DIFF_OP_DELETE));
diff --git a/src/hash_table.c b/src/hash_table.c
index 20391ec..e181a11 100644
--- a/src/hash_table.c
+++ b/src/hash_table.c
@@ -25,6 +25,8 @@
#include "dict.h"
#include "log.h"
+#define LYDICT_MIN_SIZE 1024
+
/**
* @brief Comparison callback for dictionary's hash table
*
@@ -53,7 +55,7 @@
{
LY_CHECK_ARG_RET(NULL, dict, );
- dict->hash_tab = lyht_new(1024, sizeof(struct dict_rec), lydict_val_eq, NULL, 1);
+ dict->hash_tab = lyht_new(LYDICT_MIN_SIZE, sizeof(struct dict_rec), lydict_val_eq, NULL, 1);
LY_CHECK_ERR_RET(!dict->hash_tab, LOGINT(NULL), );
pthread_mutex_init(&dict->lock, NULL);
}
@@ -680,7 +682,7 @@
/* check size & enlarge if needed */
++ht->used;
if (ht->resize) {
- r = (ht->used * 100) / ht->size;
+ r = (ht->used * LYHT_HUNDRED_PERCENTAGE) / ht->size;
if ((ht->resize == 1) && (r >= LYHT_FIRST_SHRINK_PERCENTAGE)) {
/* enable shrinking */
ht->resize = 2;
@@ -760,7 +762,7 @@
/* check size & shrink if needed */
--ht->used;
if (ht->resize == 2) {
- r = (ht->used * 100) / ht->size;
+ r = (ht->used * LYHT_HUNDRED_PERCENTAGE) / ht->size;
if ((r < LYHT_SHRINK_PERCENTAGE) && (ht->size > LYHT_MIN_SIZE)) {
if (resize_val_equal) {
old_val_equal = lyht_set_cb(ht, resize_val_equal);
diff --git a/src/hash_table.h b/src/hash_table.h
index 8e135b0..2e7a511 100644
--- a/src/hash_table.h
+++ b/src/hash_table.h
@@ -49,6 +49,9 @@
*/
typedef ly_bool (*values_equal_cb)(void *val1_p, void *val2_p, ly_bool mod, void *cb_data);
+/** reference value for 100% */
+#define LYHT_HUNDRED_PERCENTAGE 100
+
/** when the table is at least this much percent full, it is enlarged (double the size) */
#define LYHT_ENLARGE_PERCENTAGE 75
diff --git a/src/json.c b/src/json.c
index 1c3e99c..4642683 100644
--- a/src/json.c
+++ b/src/json.c
@@ -71,7 +71,8 @@
{
/* skip leading whitespaces */
while (*jsonctx->in->current != '\0' && is_jsonws(*jsonctx->in->current)) {
- if (*jsonctx->in->current == 0x0a) { /* new line */
+ if (*jsonctx->in->current == '\n') {
+ /* new line */
jsonctx->line++;
}
ly_in_skip(jsonctx->in, 1);
@@ -226,11 +227,11 @@
} else if (isdigit(in[offset + i])) {
u = (in[offset + i] - '0');
} else if (in[offset + i] > 'F') {
- u = 10 + (in[offset + i] - 'a');
+ u = LY_BASE_DEC + (in[offset + i] - 'a');
} else {
- u = 10 + (in[offset + i] - 'A');
+ u = LY_BASE_DEC + (in[offset + i] - 'A');
}
- value = (16 * value) + u;
+ value = (LY_BASE_HEX * value) + u;
}
break;
default:
@@ -383,7 +384,7 @@
int64_t dp_position; /* final position of the deciaml point */
errno = 0;
- e_val = strtol(e_ptr, &ptr, 10);
+ e_val = strtol(e_ptr, &ptr, LY_BASE_DEC);
if (errno) {
LOGVAL(jsonctx->ctx, LY_VLOG_LINE, &jsonctx->line, LYVE_SEMANTICS,
"Exponent out-of-bounds in a JSON Number value (%.*s).", offset - minus - (e_ptr - in), e_ptr);
@@ -561,24 +562,24 @@
return LY_SUCCESS;
}
- if ((*jsonctx->in->current == 'f') && !strncmp(jsonctx->in->current, "false", 5)) {
+ if ((*jsonctx->in->current == 'f') && !strncmp(jsonctx->in->current, "false", ly_strlen_const("false"))) {
/* false */
- lyjson_ctx_set_value(jsonctx, jsonctx->in->current, 5, 0);
- ly_in_skip(jsonctx->in, 5);
+ lyjson_ctx_set_value(jsonctx, jsonctx->in->current, ly_strlen_const("false"), 0);
+ ly_in_skip(jsonctx->in, ly_strlen_const("false"));
JSON_PUSH_STATUS_RET(jsonctx, LYJSON_FALSE);
LY_CHECK_RET(lyjson_check_next(jsonctx));
- } else if ((*jsonctx->in->current == 't') && !strncmp(jsonctx->in->current, "true", 4)) {
+ } else if ((*jsonctx->in->current == 't') && !strncmp(jsonctx->in->current, "true", ly_strlen_const("true"))) {
/* true */
- lyjson_ctx_set_value(jsonctx, jsonctx->in->current, 4, 0);
- ly_in_skip(jsonctx->in, 4);
+ lyjson_ctx_set_value(jsonctx, jsonctx->in->current, ly_strlen_const("true"), 0);
+ ly_in_skip(jsonctx->in, ly_strlen_const("true"));
JSON_PUSH_STATUS_RET(jsonctx, LYJSON_TRUE);
LY_CHECK_RET(lyjson_check_next(jsonctx));
- } else if ((*jsonctx->in->current == 'n') && !strncmp(jsonctx->in->current, "null", 4)) {
+ } else if ((*jsonctx->in->current == 'n') && !strncmp(jsonctx->in->current, "null", ly_strlen_const("null"))) {
/* none */
lyjson_ctx_set_value(jsonctx, jsonctx->in->current, 0, 0);
- ly_in_skip(jsonctx->in, 4);
+ ly_in_skip(jsonctx->in, ly_strlen_const("null"));
JSON_PUSH_STATUS_RET(jsonctx, LYJSON_NULL);
LY_CHECK_RET(lyjson_check_next(jsonctx));
diff --git a/src/lyb.h b/src/lyb.h
index 1928ba5..bb72f0b 100644
--- a/src/lyb.h
+++ b/src/lyb.h
@@ -152,6 +152,16 @@
/* Just a helper macro */
#define LYB_META_BYTES (LYB_INCHUNK_BYTES + LYB_SIZE_BYTES)
+#define LYB_BYTE_MASK 0xff
+
+/* model revision as XXXX XXXX XXXX XXXX (2B) (year is offset from 2000)
+ * YYYY YYYM MMMD DDDD */
+#define LYB_REV_YEAR_OFFSET 2000
+#define LYB_REV_YEAR_MASK 0xfe00U
+#define LYB_REV_YEAR_SHIFT 9
+#define LYB_REV_MONTH_MASK 0x01E0U
+#define LYB_REV_MONTH_SHIFT 5
+#define LYB_REV_DAY_MASK 0x001fU
/* Type large enough for all meta data */
#define LYB_META uint16_t
diff --git a/src/parser_json.c b/src/parser_json.c
index be2aa30..3f426a4 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1324,7 +1324,8 @@
/* starting top-level */
for (i = 0; in->current[i] != '\0' && is_jsonws(in->current[i]); i++) {
- if (in->current[i] == 0x0a) { /* new line */
+ if (in->current[i] == '\n') {
+ /* new line */
line++;
}
}
@@ -1444,12 +1445,14 @@
/* now the notificationContent is expected, which will be parsed by the caller */
/* create notification envelope */
- ret = lyd_create_opaq(jsonctx->ctx, "notification", 12, NULL, 0, "ietf-restconf", 13, "", 0, NULL, LY_PREF_JSON,
- NULL, LYD_NODEHINT_ENVELOPE, envp_p);
+ ret = lyd_create_opaq(jsonctx->ctx, "notification", ly_strlen_const("notification"), NULL, 0,
+ "ietf-restconf", ly_strlen_const("ietf-restconf"), "", ly_strlen_const(""), NULL, LY_PREF_JSON, NULL,
+ LYD_NODEHINT_ENVELOPE, envp_p);
LY_CHECK_GOTO(ret, cleanup);
/* create notification envelope */
- ret = lyd_create_opaq(jsonctx->ctx, "eventTime", 9, NULL, 0, "ietf-restconf", 13, value, value_len, &dynamic,
- LY_PREF_JSON, NULL, LYD_VALHINT_STRING, &et);
+ ret = lyd_create_opaq(jsonctx->ctx, "eventTime", ly_strlen_const("eventTime"), NULL, 0,
+ "ietf-restconf", ly_strlen_const("ietf-restconf"), value, value_len, &dynamic, LY_PREF_JSON, NULL,
+ LYD_VALHINT_STRING, &et);
LY_CHECK_GOTO(ret, cleanup);
/* insert eventTime into notification */
lyd_insert_node(*envp_p, NULL, et);
diff --git a/src/parser_lyb.c b/src/parser_lyb.c
index fc48cd9..cb7caff 100644
--- a/src/parser_lyb.c
+++ b/src/parser_lyb.c
@@ -149,16 +149,16 @@
buf = le64toh(buf);
switch (num_size) {
- case 1:
+ case sizeof(uint8_t):
*((uint8_t *)num) = buf;
break;
- case 2:
+ case sizeof(uint16_t):
*((uint16_t *)num) = buf;
break;
- case 4:
+ case sizeof(uint32_t):
*((uint32_t *)num) = buf;
break;
- case 8:
+ case sizeof(uint64_t):
*((uint64_t *)num) = buf;
break;
default:
@@ -278,7 +278,7 @@
lyb_parse_model(struct lylyb_ctx *lybctx, uint32_t parse_options, const struct lys_module **mod)
{
LY_ERR ret = LY_SUCCESS;
- char *mod_name = NULL, mod_rev[11];
+ char *mod_name = NULL, mod_rev[LY_REV_SIZE];
uint16_t rev;
/* model name */
@@ -295,7 +295,8 @@
}
if (rev) {
- sprintf(mod_rev, "%04u-%02u-%02u", ((rev & 0xFE00) >> 9) + 2000, (rev & 0x01E0) >> 5, rev & 0x001Fu);
+ sprintf(mod_rev, "%04u-%02u-%02u", ((rev & LYB_REV_YEAR_MASK) >> LYB_REV_YEAR_SHIFT) + LYB_REV_YEAR_OFFSET,
+ (rev & LYB_REV_MONTH_MASK) >> LYB_REV_MONTH_SHIFT, rev & LYB_REV_DAY_MASK);
*mod = ly_ctx_get_module(lybctx->ctx, mod_name, mod_rev);
if ((parse_options & LYD_PARSE_LYB_MOD_UPDATE) && !(*mod)) {
/* try to use an updated module */
diff --git a/src/parser_stmt.c b/src/parser_stmt.c
index f2fe35f..5cca207 100644
--- a/src/parser_stmt.c
+++ b/src/parser_stmt.c
@@ -251,11 +251,11 @@
LY_CHECK_RET(lysp_stmt_validate_value(ctx, Y_STR_ARG, stmt->arg));
arg_len = strlen(stmt->arg);
- if ((arg_len == 7) && !strncmp(stmt->arg, "current", arg_len)) {
+ if ((arg_len == ly_strlen_const("current")) && !strncmp(stmt->arg, "current", arg_len)) {
*flags |= LYS_STATUS_CURR;
- } else if ((arg_len == 10) && !strncmp(stmt->arg, "deprecated", arg_len)) {
+ } else if ((arg_len == ly_strlen_const("deprecated")) && !strncmp(stmt->arg, "deprecated", arg_len)) {
*flags |= LYS_STATUS_DEPRC;
- } else if ((arg_len == 8) && !strncmp(stmt->arg, "obsolete", arg_len)) {
+ } else if ((arg_len == ly_strlen_const("obsolete")) && !strncmp(stmt->arg, "obsolete", arg_len)) {
*flags |= LYS_STATUS_OBSLT;
} else {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, arg_len, stmt->arg, "status");
@@ -386,13 +386,13 @@
errno = 0;
if (val_kw == LY_STMT_VALUE) {
- num = strtol(stmt->arg, &ptr, 10);
+ num = strtol(stmt->arg, &ptr, LY_BASE_DEC);
if ((num < INT64_C(-2147483648)) || (num > INT64_C(2147483647))) {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, arg_len, stmt->arg, ly_stmt2str(val_kw));
goto error;
}
} else {
- unum = strtoul(stmt->arg, &ptr, 10);
+ unum = strtoul(stmt->arg, &ptr, LY_BASE_DEC);
if (unum > UINT64_C(4294967295)) {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, arg_len, stmt->arg, ly_stmt2str(val_kw));
goto error;
@@ -533,13 +533,13 @@
}
errno = 0;
- num = strtoul(stmt->arg, &ptr, 10);
+ num = strtoul(stmt->arg, &ptr, LY_BASE_DEC);
/* we have not parsed the whole argument */
if ((size_t)(ptr - stmt->arg) != arg_len) {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, arg_len, stmt->arg, "fraction-digits");
return LY_EVALID;
}
- if ((errno == ERANGE) || (num > 18)) {
+ if ((errno == ERANGE) || (num > LY_TYPE_DEC64_FD_MAX)) {
LOGVAL_PARSER(ctx, LY_VCODE_OOB, arg_len, stmt->arg, "fraction-digits");
return LY_EVALID;
}
@@ -589,9 +589,9 @@
LY_CHECK_RET(lysp_stmt_validate_value(ctx, Y_STR_ARG, stmt->arg));
arg_len = strlen(stmt->arg);
- if ((arg_len == 4) && !strncmp(stmt->arg, "true", arg_len)) {
+ if ((arg_len == ly_strlen_const("true")) && !strncmp(stmt->arg, "true", arg_len)) {
*reqinst = 1;
- } else if ((arg_len != 5) || strncmp(stmt->arg, "false", arg_len)) {
+ } else if ((arg_len != ly_strlen_const("false")) || strncmp(stmt->arg, "false", arg_len)) {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, arg_len, stmt->arg, "require-instance");
return LY_EVALID;
}
@@ -631,14 +631,14 @@
char *buf;
const struct lysp_stmt *child;
- if ((*pat)[0] == 0x15) {
+ if ((*pat)[0] == LYSP_RESTR_PATTERN_NACK) {
LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "modifier");
return LY_EVALID;
}
LY_CHECK_RET(lysp_stmt_validate_value(ctx, Y_STR_ARG, stmt->arg));
arg_len = strlen(stmt->arg);
- if ((arg_len != 12) || strncmp(stmt->arg, "invert-match", arg_len)) {
+ if ((arg_len != ly_strlen_const("invert-match")) || strncmp(stmt->arg, "invert-match", arg_len)) {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, arg_len, stmt->arg, "modifier");
return LY_EVALID;
}
@@ -649,8 +649,8 @@
strcpy(buf, *pat);
lydict_remove(PARSER_CTX(ctx), *pat);
- assert(buf[0] == 0x06);
- buf[0] = 0x15;
+ assert(buf[0] == LYSP_RESTR_PATTERN_ACK);
+ buf[0] = LYSP_RESTR_PATTERN_NACK;
LY_CHECK_RET(lydict_insert_zc(PARSER_CTX(ctx), buf, pat));
for (child = stmt->child; child; child = child->next) {
@@ -696,7 +696,7 @@
buf = malloc(arg_len + 2);
LY_CHECK_ERR_RET(!buf, LOGMEM(PARSER_CTX(ctx)), LY_EMEM);
memmove(buf + 1, stmt->arg, arg_len);
- buf[0] = 0x06; /* pattern's default regular-match flag */
+ buf[0] = LYSP_RESTR_PATTERN_ACK; /* pattern's default regular-match flag */
buf[arg_len + 1] = '\0'; /* terminating NULL byte */
LY_CHECK_RET(lydict_insert_zc(PARSER_CTX(ctx), buf, &restr->arg.str));
restr->arg.mod = ctx->parsed_mod;
diff --git a/src/parser_xml.c b/src/parser_xml.c
index 21b30ad..432bb7d 100644
--- a/src/parser_xml.c
+++ b/src/parser_xml.c
@@ -876,8 +876,8 @@
}*/
/* create node */
- ret = lyd_create_opaq(xmlctx->ctx, "eventTime", 9, prefix, prefix_len, ns->uri, strlen(ns->uri), xmlctx->value,
- xmlctx->value_len, NULL, LY_PREF_XML, NULL, LYD_NODEHINT_ENVELOPE, &et);
+ ret = lyd_create_opaq(xmlctx->ctx, "eventTime", ly_strlen_const("eventTime"), prefix, prefix_len,
+ ns->uri, strlen(ns->uri), xmlctx->value, xmlctx->value_len, NULL, LY_PREF_XML, NULL, LYD_NODEHINT_ENVELOPE, &et);
LY_CHECK_GOTO(ret, cleanup);
/* assign atributes */
diff --git a/src/parser_yang.c b/src/parser_yang.c
index 28c7785..9df5183 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -104,8 +104,9 @@
LY_ERR
buf_add_char(struct ly_ctx *ctx, struct ly_in *in, size_t len, char **buf, size_t *buf_len, size_t *buf_used)
{
+#define BUF_STEP 16;
if (*buf_len <= (*buf_used) + len) {
- *buf_len += 16;
+ *buf_len += BUF_STEP;
*buf = ly_realloc(*buf, *buf_len);
LY_CHECK_ERR_RET(!*buf, LOGMEM(ctx), LY_EMEM);
}
@@ -117,6 +118,7 @@
(*buf_used) += len;
return LY_SUCCESS;
+#undef BUF_STEP
}
/**
@@ -223,34 +225,35 @@
LY_ERR
skip_comment(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint8_t comment)
{
- /* internal statuses: 0 - comment ended,
- * 1 - in line comment,
- * 2 - in block comment,
- * 3 - in block comment with last read character '*'
- */
+ /* internal statuses: */
+#define COMMENT_NO 0 /* comment ended */
+#define COMMENT_LINE 1 /* in line comment */
+#define COMMENT_BLOCK 2 /* in block comment */
+#define COMMENT_BLOCK_END 3 /* in block comment with last read character '*' */
+
while (in->current[0] && comment) {
switch (comment) {
- case 1:
+ case COMMENT_LINE:
if (in->current[0] == '\n') {
- comment = 0;
+ comment = COMMENT_NO;
++ctx->line;
}
break;
- case 2:
+ case COMMENT_BLOCK:
if (in->current[0] == '*') {
- comment = 3;
+ comment = COMMENT_BLOCK_END;
} else if (in->current[0] == '\n') {
++ctx->line;
}
break;
- case 3:
+ case COMMENT_BLOCK_END:
if (in->current[0] == '/') {
- comment = 0;
+ comment = COMMENT_NO;
} else if (in->current[0] != '*') {
if (in->current[0] == '\n') {
++ctx->line;
}
- comment = 2;
+ comment = COMMENT_BLOCK;
}
break;
default:
@@ -265,12 +268,17 @@
++in->current;
}
- if (!in->current[0] && (comment > 1)) {
+ if (!in->current[0] && (comment >= COMMENT_BLOCK)) {
LOGVAL_PARSER(ctx, LYVE_SYNTAX, "Unexpected end-of-input, non-terminated comment.");
return LY_EVALID;
}
return LY_SUCCESS;
+
+#undef COMMENT_NO
+#undef COMMENT_LINE
+#undef COMMENT_BLOCK
+#undef COMMENT_BLOCK_END
}
/**
@@ -293,9 +301,14 @@
read_qstring(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum yang_arg arg, char **word_p, char **word_b,
size_t *word_len, size_t *buf_len)
{
- /* string: 0 - string ended, 1 - string with ', 2 - string with ", 3 - string with " with last character \,
- * 4 - string finished, now skipping whitespaces looking for +,
- * 5 - string continues after +, skipping whitespaces */
+ /* string parsing status: */
+#define STRING_ENDED 0 /* string ended */
+#define STRING_SINGLE_QUOTED 1 /* string with ' */
+#define STRING_DOUBLE_QUOTED 2 /* string with " */
+#define STRING_DOUBLE_QUOTED_ESCAPED 3 /* string with " with last character \ */
+#define STRING_PAUSED_NEXTSTRING 4 /* string finished, now skipping whitespaces looking for + */
+#define STRING_PAUSED_CONTINUE 5 /* string continues after +, skipping whitespaces */
+
uint8_t string;
uint64_t block_indent = 0, current_indent = 0;
ly_bool need_buf = 0;
@@ -304,21 +317,21 @@
uint64_t trailing_ws = 0; /* current number of stored trailing whitespace characters */
if (in->current[0] == '\"') {
- string = 2;
+ string = STRING_DOUBLE_QUOTED;
current_indent = block_indent = ctx->indent + 1;
} else {
assert(in->current[0] == '\'');
- string = 1;
+ string = STRING_SINGLE_QUOTED;
}
MOVE_INPUT(ctx, in, 1);
while (in->current[0] && string) {
switch (string) {
- case 1:
+ case STRING_SINGLE_QUOTED:
switch (in->current[0]) {
case '\'':
/* string may be finished, but check for + */
- string = 4;
+ string = STRING_PAUSED_NEXTSTRING;
MOVE_INPUT(ctx, in, 1);
break;
default:
@@ -327,17 +340,17 @@
break;
}
break;
- case 2:
+ case STRING_DOUBLE_QUOTED:
switch (in->current[0]) {
case '\"':
/* string may be finished, but check for + */
- string = 4;
+ string = STRING_PAUSED_NEXTSTRING;
MOVE_INPUT(ctx, in, 1);
trailing_ws = 0;
break;
case '\\':
/* special character following */
- string = 3;
+ string = STRING_DOUBLE_QUOTED_ESCAPED;
/* the backslash sequence is substituted, so we will need a buffer to store the result */
need_buf = 1;
@@ -365,8 +378,8 @@
case '\t':
if (current_indent < block_indent) {
assert(need_buf);
- current_indent += 8;
- ctx->indent += 8;
+ current_indent += Y_TAB_SPACES;
+ ctx->indent += Y_TAB_SPACES;
for ( ; current_indent > block_indent; --current_indent, --ctx->indent) {
/* store leftover spaces from the tab */
c = in->current;
@@ -381,7 +394,7 @@
LY_CHECK_RET(buf_store_char(ctx, in, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix));
trailing_ws++;
/* additional characters for indentation - only 1 was count in buf_store_char */
- ctx->indent += 7;
+ ctx->indent += Y_TAB_SPACES - 1;
}
break;
case '\n':
@@ -416,7 +429,7 @@
break;
}
break;
- case 3:
+ case STRING_DOUBLE_QUOTED_ESCAPED:
/* string encoded characters */
c = in->current;
switch (in->current[0]) {
@@ -439,19 +452,19 @@
/* check and store character */
LY_CHECK_RET(buf_store_char(ctx, in, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix));
- string = 2;
+ string = STRING_DOUBLE_QUOTED;
in->current = c + 1;
break;
- case 4:
+ case STRING_PAUSED_NEXTSTRING:
switch (in->current[0]) {
case '+':
/* string continues */
- string = 5;
+ string = STRING_PAUSED_CONTINUE;
need_buf = 1;
break;
case '\n':
++ctx->line;
- /* fallthrough */
+ /* fall through */
case ' ':
case '\t':
/* just skip */
@@ -462,20 +475,20 @@
}
MOVE_INPUT(ctx, in, 1);
break;
- case 5:
+ case STRING_PAUSED_CONTINUE:
switch (in->current[0]) {
case '\n':
++ctx->line;
- /* fallthrough */
+ /* fall through */
case ' ':
case '\t':
/* skip */
break;
case '\'':
- string = 1;
+ string = STRING_SINGLE_QUOTED;
break;
case '\"':
- string = 2;
+ string = STRING_DOUBLE_QUOTED;
break;
default:
/* it must be quoted again */
@@ -496,6 +509,13 @@
return LY_EVALID;
}
return LY_SUCCESS;
+
+#undef STRING_ENDED
+#undef STRING_SINGLE_QUOTED
+#undef STRING_DOUBLE_QUOTED
+#undef STRING_DOUBLE_QUOTED_ESCAPED
+#undef STRING_PAUSED_NEXTSTRING
+#undef STRING_PAUSED_CONTINUE
}
/**
@@ -568,7 +588,7 @@
goto str_end;
}
/* tabs count for 8 spaces */
- ctx->indent += 8;
+ ctx->indent += Y_TAB_SPACES;
++in->current;
break;
@@ -673,7 +693,7 @@
break;
case '\t':
/* skip whitespaces (optsep) */
- ctx->indent += 8;
+ ctx->indent += Y_TAB_SPACES;
break;
default:
/* either a keyword start or an invalid character */
@@ -711,7 +731,7 @@
if ((*kw == LY_STMT_INPUT) || (*kw == LY_STMT_OUTPUT)) {
break;
}
- /* fallthrough */
+ /* fall through */
default:
MOVE_INPUT(ctx, in, 1);
LOGVAL_PARSER(ctx, LY_VCODE_INSTREXP, (int)(in->current - word_start), word_start,
@@ -925,7 +945,7 @@
if ((word_len == 1) && !strncmp(word, "1", word_len)) {
*version = LYS_VERSION_1_0;
- } else if ((word_len == 3) && !strncmp(word, "1.1", word_len)) {
+ } else if ((word_len == ly_strlen_const("1.1")) && !strncmp(word, "1.1", word_len)) {
*version = LYS_VERSION_1_1;
} else {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "yang-version");
@@ -1329,9 +1349,9 @@
/* get value */
LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len));
- if ((word_len == 4) && !strncmp(word, "true", word_len)) {
+ if ((word_len == ly_strlen_const("true")) && !strncmp(word, "true", word_len)) {
*flags |= LYS_CONFIG_W;
- } else if ((word_len == 5) && !strncmp(word, "false", word_len)) {
+ } else if ((word_len == ly_strlen_const("false")) && !strncmp(word, "false", word_len)) {
*flags |= LYS_CONFIG_R;
} else {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "config");
@@ -1379,9 +1399,9 @@
/* get value */
LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len));
- if ((word_len == 4) && !strncmp(word, "true", word_len)) {
+ if ((word_len == ly_strlen_const("true")) && !strncmp(word, "true", word_len)) {
*flags |= LYS_MAND_TRUE;
- } else if ((word_len == 5) && !strncmp(word, "false", word_len)) {
+ } else if ((word_len == ly_strlen_const("false")) && !strncmp(word, "false", word_len)) {
*flags |= LYS_MAND_FALSE;
} else {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "mandatory");
@@ -1497,11 +1517,11 @@
/* get value */
LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len));
- if ((word_len == 7) && !strncmp(word, "current", word_len)) {
+ if ((word_len == ly_strlen_const("current")) && !strncmp(word, "current", word_len)) {
*flags |= LYS_STATUS_CURR;
- } else if ((word_len == 10) && !strncmp(word, "deprecated", word_len)) {
+ } else if ((word_len == ly_strlen_const("deprecated")) && !strncmp(word, "deprecated", word_len)) {
*flags |= LYS_STATUS_DEPRC;
- } else if ((word_len == 8) && !strncmp(word, "obsolete", word_len)) {
+ } else if ((word_len == ly_strlen_const("obsolete")) && !strncmp(word, "obsolete", word_len)) {
*flags |= LYS_STATUS_OBSLT;
} else {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "status");
@@ -1680,13 +1700,13 @@
errno = 0;
if (val_kw == LY_STMT_VALUE) {
- num = strtol(word, &ptr, 10);
+ num = strtol(word, &ptr, LY_BASE_DEC);
if ((num < INT64_C(-2147483648)) || (num > INT64_C(2147483647))) {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, ly_stmt2str(val_kw));
goto error;
}
} else {
- unum = strtoul(word, &ptr, 10);
+ unum = strtoul(word, &ptr, LY_BASE_DEC);
if (unum > UINT64_C(4294967295)) {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, ly_stmt2str(val_kw));
goto error;
@@ -1826,14 +1846,14 @@
}
errno = 0;
- num = strtoul(word, &ptr, 10);
+ num = strtoul(word, &ptr, LY_BASE_DEC);
/* we have not parsed the whole argument */
if ((size_t)(ptr - word) != word_len) {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "fraction-digits");
free(buf);
return LY_EVALID;
}
- if ((errno == ERANGE) || (num > 18)) {
+ if ((errno == ERANGE) || (num > LY_TYPE_DEC64_FD_MAX)) {
LOGVAL_PARSER(ctx, LY_VCODE_OOB, word_len, word, "fraction-digits");
free(buf);
return LY_EVALID;
@@ -1883,9 +1903,9 @@
/* get value */
LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len));
- if ((word_len == 4) && !strncmp(word, "true", word_len)) {
+ if ((word_len == ly_strlen_const("true")) && !strncmp(word, "true", word_len)) {
*reqinst = 1;
- } else if ((word_len != 5) || strncmp(word, "false", word_len)) {
+ } else if ((word_len != ly_strlen_const("false")) || strncmp(word, "false", word_len)) {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "require-instance");
free(buf);
return LY_EVALID;
@@ -1924,7 +1944,7 @@
size_t word_len;
enum ly_stmt kw;
- if ((*pat)[0] == 0x15) {
+ if ((*pat)[0] == LYSP_RESTR_PATTERN_NACK) {
LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "modifier");
return LY_EVALID;
}
@@ -1932,7 +1952,7 @@
/* get value */
LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len));
- if ((word_len != 12) || strncmp(word, "invert-match", word_len)) {
+ if ((word_len != ly_strlen_const("invert-match")) || strncmp(word, "invert-match", word_len)) {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "modifier");
free(buf);
return LY_EVALID;
@@ -1945,8 +1965,8 @@
strcpy(buf, *pat);
lydict_remove(PARSER_CTX(ctx), *pat);
- assert(buf[0] == 0x06);
- buf[0] = 0x15;
+ assert(buf[0] == LYSP_RESTR_PATTERN_ACK);
+ buf[0] = LYSP_RESTR_PATTERN_NACK;
LY_CHECK_RET(lydict_insert_zc(PARSER_CTX(ctx), buf, pat));
YANG_READ_SUBSTMT_FOR(ctx, in, kw, word, word_len, ret, ) {
@@ -1987,14 +2007,14 @@
/* add special meaning first byte */
if (buf) {
- buf = ly_realloc(buf, word_len + 2);
+ buf = ly_realloc(buf, word_len + 2);
word = buf;
} else {
buf = malloc(word_len + 2);
}
LY_CHECK_ERR_RET(!buf, LOGMEM(PARSER_CTX(ctx)), LY_EMEM);
memmove(buf + 1, word, word_len);
- buf[0] = 0x06; /* pattern's default regular-match flag */
+ buf[0] = LYSP_RESTR_PATTERN_ACK; /* pattern's default regular-match flag */
buf[word_len + 1] = '\0'; /* terminating NULL byte */
LY_CHECK_RET(lydict_insert_zc(PARSER_CTX(ctx), buf, &restr->arg.str));
restr->arg.mod = ctx->parsed_mod;
@@ -2257,7 +2277,7 @@
if (ly_strncmp("unbounded", word, word_len)) {
errno = 0;
- num = strtoul(word, &ptr, 10);
+ num = strtoul(word, &ptr, LY_BASE_DEC);
/* we have not parsed the whole argument */
if ((size_t)(ptr - word) != word_len) {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "max-elements");
@@ -2324,7 +2344,7 @@
}
errno = 0;
- num = strtoul(word, &ptr, 10);
+ num = strtoul(word, &ptr, LY_BASE_DEC);
/* we have not parsed the whole argument */
if ((size_t)(ptr - word) != word_len) {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "min-elements");
@@ -2378,9 +2398,9 @@
/* get value */
LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len));
- if ((word_len == 6) && !strncmp(word, "system", word_len)) {
+ if ((word_len == ly_strlen_const("system")) && !strncmp(word, "system", word_len)) {
*flags |= LYS_ORDBY_SYSTEM;
- } else if ((word_len == 4) && !strncmp(word, "user", word_len)) {
+ } else if ((word_len == ly_strlen_const("user")) && !strncmp(word, "user", word_len)) {
*flags |= LYS_ORDBY_USER;
} else {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "ordered-by");
@@ -3577,9 +3597,9 @@
/* get value */
LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len));
- if ((word_len == 4) && !strncmp(word, "true", word_len)) {
+ if ((word_len == ly_strlen_const("true")) && !strncmp(word, "true", word_len)) {
*flags |= LYS_YINELEM_TRUE;
- } else if ((word_len == 5) && !strncmp(word, "false", word_len)) {
+ } else if ((word_len == ly_strlen_const("false")) && !strncmp(word, "false", word_len)) {
*flags |= LYS_YINELEM_FALSE;
} else {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "yin-element");
@@ -3724,13 +3744,13 @@
/* get value */
LY_CHECK_RET(get_argument(ctx, in, Y_STR_ARG, NULL, &word, &buf, &word_len));
- if ((word_len == 13) && !strncmp(word, "not-supported", word_len)) {
+ if ((word_len == ly_strlen_const("not-supported")) && !strncmp(word, "not-supported", word_len)) {
dev_mod = LYS_DEV_NOT_SUPPORTED;
- } else if ((word_len == 3) && !strncmp(word, "add", word_len)) {
+ } else if ((word_len == ly_strlen_const("add")) && !strncmp(word, "add", word_len)) {
dev_mod = LYS_DEV_ADD;
- } else if ((word_len == 7) && !strncmp(word, "replace", word_len)) {
+ } else if ((word_len == ly_strlen_const("replace")) && !strncmp(word, "replace", word_len)) {
dev_mod = LYS_DEV_REPLACE;
- } else if ((word_len == 6) && !strncmp(word, "delete", word_len)) {
+ } else if ((word_len == ly_strlen_const("delete")) && !strncmp(word, "delete", word_len)) {
dev_mod = LYS_DEV_DELETE;
} else {
LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "deviate");
diff --git a/src/parser_yin.c b/src/parser_yin.c
index ab73964..bbab210 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -585,11 +585,11 @@
{
LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx));
LY_CHECK_RET(yin_parse_attribute(ctx, arg_type, value, arg_val_type, kw));
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
- return yin_parse_content(ctx, subelems, 1, kw, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), kw, NULL, exts);
}
/**
@@ -639,13 +639,13 @@
LY_CHECK_ERR_RET(!saved_value, LOGMEM(ctx->xmlctx->ctx), LY_EMEM);
memmove(saved_value + 1, real_value, len);
FREE_STRING(ctx->xmlctx->ctx, real_value);
- saved_value[0] = 0x06;
+ saved_value[0] = LYSP_RESTR_PATTERN_ACK;
saved_value[len + 1] = '\0';
LY_CHECK_RET(lydict_insert_zc(ctx->xmlctx->ctx, saved_value, &restr->arg.str));
restr->arg.mod = ctx->parsed_mod;
type->flags |= LYS_SET_PATTERN;
- struct yin_subelement subelems[6] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_DESCRIPTION, &restr->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_ERROR_APP_TAG, &restr->eapptag, YIN_SUBELEM_UNIQUE},
{LY_STMT_ERROR_MESSAGE, &restr->emsg, YIN_SUBELEM_UNIQUE},
@@ -654,7 +654,7 @@
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
- return yin_parse_content(ctx, subelems, 6, LY_STMT_PATTERN, NULL, &restr->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_PATTERN, NULL, &restr->exts);
}
/**
@@ -681,13 +681,13 @@
}
errno = 0;
- num = strtoul(temp_val, &ptr, 10);
+ num = strtoul(temp_val, &ptr, LY_BASE_DEC);
if (*ptr != '\0') {
LOGVAL_PARSER((struct lys_parser_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", "fraction-digits");
FREE_STRING(ctx->xmlctx->ctx, temp_val);
return LY_EVALID;
}
- if ((errno == ERANGE) || (num > 18)) {
+ if ((errno == ERANGE) || (num > LY_TYPE_DEC64_FD_MAX)) {
LOGVAL_PARSER((struct lys_parser_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", "fraction-digits");
FREE_STRING(ctx->xmlctx->ctx, temp_val);
return LY_EVALID;
@@ -695,11 +695,11 @@
FREE_STRING(ctx->xmlctx->ctx, temp_val);
type->fraction_digits = num;
type->flags |= LYS_SET_FRDIGITS;
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
- return yin_parse_content(ctx, subelems, 1, LY_STMT_FRACTION_DIGITS, NULL, &type->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_FRACTION_DIGITS, NULL, &type->exts);
}
/**
@@ -722,7 +722,7 @@
CHECK_NONEMPTY((struct lys_parser_ctx *)ctx, strlen(en->name), "enum");
CHECK_UNIQUENESS((struct lys_parser_ctx *)ctx, type->enums, name, "enum", en->name);
- struct yin_subelement subelems[6] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_DESCRIPTION, &en->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_IF_FEATURE, &en->iffeatures, 0},
{LY_STMT_REFERENCE, &en->ref, YIN_SUBELEM_UNIQUE},
@@ -731,7 +731,7 @@
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
- return yin_parse_content(ctx, subelems, 6, LY_STMT_ENUM, NULL, &en->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_ENUM, NULL, &en->exts);
}
/**
@@ -752,7 +752,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &en->name, Y_IDENTIF_ARG, LY_STMT_BIT));
CHECK_UNIQUENESS((struct lys_parser_ctx *)ctx, type->enums, name, "bit", en->name);
- struct yin_subelement subelems[6] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_DESCRIPTION, &en->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_IF_FEATURE, &en->iffeatures, 0},
{LY_STMT_POSITION, en, YIN_SUBELEM_UNIQUE},
@@ -761,7 +761,7 @@
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
- return yin_parse_content(ctx, subelems, 6, LY_STMT_BIT, NULL, &en->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_BIT, NULL, &en->exts);
}
/**
@@ -784,14 +784,14 @@
LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *values, value, LY_EMEM);
LY_ARRAY_COUNT_TYPE index = LY_ARRAY_COUNT(*values) - 1;
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, &index, 0}
};
LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx));
LY_CHECK_RET(yin_parse_attribute(ctx, arg_type, value, arg_val_type, kw));
- return yin_parse_content(ctx, subelems, 1, kw, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), kw, NULL, exts);
}
/**
@@ -861,7 +861,7 @@
yin_pasrse_reqinstance(struct lys_yin_parser_ctx *ctx, struct lysp_type *type)
{
const char *temp_val = NULL;
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
@@ -878,7 +878,7 @@
}
FREE_STRING(ctx->xmlctx->ctx, temp_val);
- return yin_parse_content(ctx, subelems, 1, LY_STMT_REQUIRE_INSTANCE, NULL, &type->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_REQUIRE_INSTANCE, NULL, &type->exts);
}
/**
@@ -896,7 +896,7 @@
assert(**pat == 0x06);
const char *temp_val;
char *modified_val;
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
@@ -917,10 +917,10 @@
lydict_remove(ctx->xmlctx->ctx, *pat);
/* modify the new value */
- modified_val[0] = 0x15;
+ modified_val[0] = LYSP_RESTR_PATTERN_NACK;
LY_CHECK_RET(lydict_insert_zc(ctx->xmlctx->ctx, modified_val, pat));
- return yin_parse_content(ctx, subelems, 1, LY_STMT_MODIFIER, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_MODIFIER, NULL, exts);
}
/**
@@ -934,7 +934,7 @@
yin_parse_restriction(struct lys_yin_parser_ctx *ctx, enum ly_stmt restr_kw, struct lysp_restr *restr)
{
assert(restr_kw == LY_STMT_MUST || restr_kw == LY_STMT_LENGTH || restr_kw == LY_STMT_RANGE);
- struct yin_subelement subelems[5] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_DESCRIPTION, &restr->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_ERROR_APP_TAG, &restr->eapptag, YIN_SUBELEM_UNIQUE},
{LY_STMT_ERROR_MESSAGE, &restr->emsg, YIN_SUBELEM_UNIQUE},
@@ -948,7 +948,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, arg_type, &restr->arg.str, Y_STR_ARG, restr_kw));
restr->arg.mod = ctx->parsed_mod;
- return yin_parse_content(ctx, subelems, 5, restr_kw, NULL, &restr->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), restr_kw, NULL, &restr->exts);
}
/**
@@ -1079,13 +1079,13 @@
/* convert value */
errno = 0;
if (kw == LY_STMT_VALUE) {
- num = strtol(temp_val, &ptr, 10);
+ num = strtol(temp_val, &ptr, LY_BASE_DEC);
if ((num < INT64_C(-2147483648)) || (num > INT64_C(2147483647))) {
LOGVAL_PARSER((struct lys_parser_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", ly_stmt2str(kw));
goto error;
}
} else {
- unum = strtoul(temp_val, &ptr, 10);
+ unum = strtoul(temp_val, &ptr, LY_BASE_DEC);
if (unum > UINT64_C(4294967295)) {
LOGVAL_PARSER((struct lys_parser_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", ly_stmt2str(kw));
goto error;
@@ -1109,11 +1109,11 @@
FREE_STRING(ctx->xmlctx->ctx, temp_val);
/* parse subelements */
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
- return yin_parse_content(ctx, subelems, 1, kw, NULL, &enm->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), kw, NULL, &enm->exts);
error:
FREE_STRING(ctx->xmlctx->ctx, temp_val);
@@ -1133,7 +1133,7 @@
yin_parse_belongs_to(struct lys_yin_parser_ctx *ctx, struct lysp_submodule *submod, struct lysp_ext_instance **exts)
{
const char *belongsto;
- struct yin_subelement subelems[2] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_PREFIX, &submod->prefix, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE},
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
@@ -1148,7 +1148,7 @@
}
lydict_remove(ctx->xmlctx->ctx, belongsto);
- return yin_parse_content(ctx, subelems, 2, LY_STMT_BELONGS_TO, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_BELONGS_TO, NULL, exts);
}
/**
@@ -1167,7 +1167,7 @@
{
assert(elem_type == LY_STMT_ORGANIZATION || elem_type == LY_STMT_CONTACT || elem_type == LY_STMT_DESCRIPTION || elem_type == LY_STMT_REFERENCE);
- struct yin_subelement subelems[2] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
{LY_STMT_ARG_TEXT, value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE | YIN_SUBELEM_FIRST}
};
@@ -1177,7 +1177,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NONE, NULL, Y_MAYBE_STR_ARG, elem_type));
/* parse content */
- return yin_parse_content(ctx, subelems, 2, elem_type, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), elem_type, NULL, exts);
}
/**
@@ -1192,7 +1192,7 @@
static LY_ERR
yin_parse_err_msg(struct lys_yin_parser_ctx *ctx, const char **value, struct lysp_ext_instance **exts)
{
- struct yin_subelement subelems[2] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
{LY_STMT_ARG_VALUE, value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE | YIN_SUBELEM_FIRST}
};
@@ -1201,7 +1201,7 @@
LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx));
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NONE, NULL, Y_MAYBE_STR_ARG, LY_STMT_ERROR_MESSAGE));
- return yin_parse_content(ctx, subelems, 2, LY_STMT_ERROR_MESSAGE, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_ERROR_MESSAGE, NULL, exts);
}
/**
@@ -1236,7 +1236,7 @@
type = nested_type;
}
- struct yin_subelement subelems[11] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_BASE, type, 0},
{LY_STMT_BIT, type, 0},
{LY_STMT_ENUM, type, 0},
@@ -1252,7 +1252,7 @@
LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx));
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &type->name, Y_PREF_IDENTIF_ARG, LY_STMT_TYPE));
- return yin_parse_content(ctx, subelems, 11, LY_STMT_TYPE, NULL, &type->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_TYPE, NULL, &type->exts);
}
/**
@@ -1271,7 +1271,7 @@
const char *temp_val = NULL;
char *ptr;
unsigned long int num;
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
@@ -1286,7 +1286,7 @@
if (strcmp(temp_val, "unbounded")) {
errno = 0;
- num = strtoul(temp_val, &ptr, 10);
+ num = strtoul(temp_val, &ptr, LY_BASE_DEC);
if (*ptr != '\0') {
LOGVAL_PARSER((struct lys_parser_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", "max-elements");
FREE_STRING(ctx->xmlctx->ctx, temp_val);
@@ -1300,7 +1300,7 @@
*max = num;
}
FREE_STRING(ctx->xmlctx->ctx, temp_val);
- return yin_parse_content(ctx, subelems, 1, LY_STMT_MAX_ELEMENTS, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_MAX_ELEMENTS, NULL, exts);
}
/**
@@ -1319,7 +1319,7 @@
const char *temp_val = NULL;
char *ptr;
unsigned long int num;
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
@@ -1334,7 +1334,7 @@
}
errno = 0;
- num = strtoul(temp_val, &ptr, 10);
+ num = strtoul(temp_val, &ptr, LY_BASE_DEC);
if (ptr[0] != 0) {
LOGVAL_PARSER((struct lys_parser_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", "min-elements");
FREE_STRING(ctx->xmlctx->ctx, temp_val);
@@ -1347,7 +1347,7 @@
}
*min = num;
FREE_STRING(ctx->xmlctx->ctx, temp_val);
- return yin_parse_content(ctx, subelems, 1, LY_STMT_MIN_ELEMENTS, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_MIN_ELEMENTS, NULL, exts);
}
/**
@@ -1409,7 +1409,7 @@
yin_parse_orderedby(struct lys_yin_parser_ctx *ctx, uint16_t *flags, struct lysp_ext_instance **exts)
{
const char *temp_val;
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
@@ -1427,7 +1427,7 @@
}
FREE_STRING(ctx->xmlctx->ctx, temp_val);
- return yin_parse_content(ctx, subelems, 1, LY_STMT_ORDERED_BY, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_ORDERED_BY, NULL, exts);
}
/**
@@ -1453,7 +1453,7 @@
LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx));
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &any->name, Y_IDENTIF_ARG, any_kw));
- struct yin_subelement subelems[9] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_CONFIG, &any->flags, YIN_SUBELEM_UNIQUE},
{LY_STMT_DESCRIPTION, &any->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_IF_FEATURE, &any->iffeatures, 0},
@@ -1465,7 +1465,7 @@
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- return yin_parse_content(ctx, subelems, 9, any_kw, NULL, &any->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), any_kw, NULL, &any->exts);
}
/**
@@ -1491,7 +1491,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &leaf->name, Y_IDENTIF_ARG, LY_STMT_LEAF));
/* parse content */
- struct yin_subelement subelems[12] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_CONFIG, &leaf->flags, YIN_SUBELEM_UNIQUE},
{LY_STMT_DEFAULT, &leaf->dflt, YIN_SUBELEM_UNIQUE},
{LY_STMT_DESCRIPTION, &leaf->dsc, YIN_SUBELEM_UNIQUE},
@@ -1506,7 +1506,7 @@
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- return yin_parse_content(ctx, subelems, 12, LY_STMT_LEAF, NULL, &leaf->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_LEAF, NULL, &leaf->exts);
}
/**
@@ -1532,7 +1532,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &llist->name, Y_IDENTIF_ARG, LY_STMT_LEAF_LIST));
/* parse content */
- struct yin_subelement subelems[14] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_CONFIG, &llist->flags, YIN_SUBELEM_UNIQUE},
{LY_STMT_DEFAULT, &llist->dflts, 0},
{LY_STMT_DESCRIPTION, &llist->dsc, YIN_SUBELEM_UNIQUE},
@@ -1549,7 +1549,7 @@
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- LY_CHECK_RET(yin_parse_content(ctx, subelems, 14, LY_STMT_LEAF_LIST, NULL, &llist->exts));
+ LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_LEAF_LIST, NULL, &llist->exts));
/* check invalid combination of subelements */
if ((llist->min) && (llist->dflts)) {
@@ -1585,7 +1585,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &tpdf->name, Y_IDENTIF_ARG, LY_STMT_TYPEDEF));
/* parse content */
- struct yin_subelement subelems[7] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_DEFAULT, &tpdf->dflt, YIN_SUBELEM_UNIQUE},
{LY_STMT_DESCRIPTION, &tpdf->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_REFERENCE, &tpdf->ref, YIN_SUBELEM_UNIQUE},
@@ -1595,7 +1595,7 @@
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- LY_CHECK_RET(yin_parse_content(ctx, subelems, 7, LY_STMT_TYPEDEF, NULL, &tpdf->exts));
+ LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_TYPEDEF, NULL, &tpdf->exts));
/* store data for collision check */
if (typedef_meta->parent && !(typedef_meta->parent->nodetype & (LYS_GROUPING | LYS_RPC | LYS_ACTION | LYS_INPUT |
@@ -1628,7 +1628,7 @@
CHECK_NONEMPTY(ctx, strlen(rf->nodeid), "refine");
/* parse content */
- struct yin_subelement subelems[11] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_CONFIG, &rf->flags, YIN_SUBELEM_UNIQUE},
{LY_STMT_DEFAULT, &rf->dflts, 0},
{LY_STMT_DESCRIPTION, &rf->dsc, YIN_SUBELEM_UNIQUE},
@@ -1642,7 +1642,7 @@
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- return yin_parse_content(ctx, subelems, 11, LY_STMT_REFINE, NULL, &rf->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_REFINE, NULL, &rf->exts);
}
/**
@@ -1669,7 +1669,7 @@
/* parse content */
struct tree_node_meta augments = {(struct lysp_node *)uses, (struct lysp_node **)&uses->augments};
- struct yin_subelement subelems[8] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_AUGMENT, &augments, 0},
{LY_STMT_DESCRIPTION, &uses->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_IF_FEATURE, &uses->iffeatures, 0},
@@ -1680,7 +1680,7 @@
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- LY_CHECK_RET(yin_parse_content(ctx, subelems, 8, LY_STMT_USES, NULL, &uses->exts));
+ LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_USES, NULL, &uses->exts));
LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, NULL, uses->augments, NULL, NULL));
return LY_SUCCESS;
@@ -1715,13 +1715,13 @@
FREE_STRING(ctx->xmlctx->ctx, temp_date);
/* parse content */
- struct yin_subelement subelems[3] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_DESCRIPTION, &rev->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_REFERENCE, &rev->ref, YIN_SUBELEM_UNIQUE},
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- return yin_parse_content(ctx, subelems, 3, LY_STMT_REVISION, NULL, &rev->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_REVISION, NULL, &rev->exts);
}
/**
@@ -1752,14 +1752,14 @@
}
/* parse content */
- struct yin_subelement subelems[4] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_DESCRIPTION, &inc->dsc, YIN_SUBELEM_UNIQUE | YIN_SUBELEM_VER2},
{LY_STMT_REFERENCE, &inc->ref, YIN_SUBELEM_UNIQUE | YIN_SUBELEM_VER2},
{LY_STMT_REVISION_DATE, &inc->rev, YIN_SUBELEM_UNIQUE},
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- return yin_parse_content(ctx, subelems, 4, LY_STMT_INCLUDE, NULL, &inc->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_INCLUDE, NULL, &inc->exts);
}
/**
@@ -1775,7 +1775,7 @@
yin_parse_revision_date(struct lys_yin_parser_ctx *ctx, char *rev, struct lysp_ext_instance **exts)
{
const char *temp_rev;
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
@@ -1787,7 +1787,7 @@
strcpy(rev, temp_rev);
FREE_STRING(ctx->xmlctx->ctx, temp_rev);
- return yin_parse_content(ctx, subelems, 1, LY_STMT_REVISION_DATE, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_REVISION_DATE, NULL, exts);
}
/**
@@ -1803,7 +1803,7 @@
yin_parse_config(struct lys_yin_parser_ctx *ctx, uint16_t *flags, struct lysp_ext_instance **exts)
{
const char *temp_val = NULL;
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
@@ -1821,7 +1821,7 @@
}
FREE_STRING(ctx->xmlctx->ctx, temp_val);
- return yin_parse_content(ctx, subelems, 1, LY_STMT_CONFIG, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_CONFIG, NULL, exts);
}
/**
@@ -1837,7 +1837,7 @@
yin_parse_yangversion(struct lys_yin_parser_ctx *ctx, uint8_t *version, struct lysp_ext_instance **exts)
{
const char *temp_version = NULL;
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
@@ -1855,7 +1855,7 @@
}
FREE_STRING(ctx->xmlctx->ctx, temp_version);
- return yin_parse_content(ctx, subelems, 1, LY_STMT_YANG_VERSION, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_YANG_VERSION, NULL, exts);
}
/**
@@ -1874,7 +1874,7 @@
/* allocate new element in sized array for import */
LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *imp_meta->imports, imp, LY_EMEM);
- struct yin_subelement subelems[5] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_DESCRIPTION, &imp->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_PREFIX, &imp->prefix, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE},
{LY_STMT_REFERENCE, &imp->ref, YIN_SUBELEM_UNIQUE},
@@ -1885,7 +1885,7 @@
/* parse import attributes */
LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx));
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_MODULE, &imp->name, Y_IDENTIF_ARG, LY_STMT_IMPORT));
- LY_CHECK_RET(yin_parse_content(ctx, subelems, 5, LY_STMT_IMPORT, NULL, &imp->exts));
+ LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_IMPORT, NULL, &imp->exts));
/* check prefix validity */
LY_CHECK_RET(lysp_check_prefix((struct lys_parser_ctx *)ctx, *imp_meta->imports, imp_meta->prefix, &imp->prefix), LY_EVALID);
@@ -1905,7 +1905,7 @@
yin_parse_mandatory(struct lys_yin_parser_ctx *ctx, uint16_t *flags, struct lysp_ext_instance **exts)
{
const char *temp_val = NULL;
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
@@ -1923,7 +1923,7 @@
}
FREE_STRING(ctx->xmlctx->ctx, temp_val);
- return yin_parse_content(ctx, subelems, 1, LY_STMT_MANDATORY, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_MANDATORY, NULL, exts);
}
/**
@@ -1939,7 +1939,7 @@
yin_parse_status(struct lys_yin_parser_ctx *ctx, uint16_t *flags, struct lysp_ext_instance **exts)
{
const char *value = NULL;
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
@@ -1959,7 +1959,7 @@
}
FREE_STRING(ctx->xmlctx->ctx, value);
- return yin_parse_content(ctx, subelems, 1, LY_STMT_STATUS, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_STATUS, NULL, exts);
}
/**
@@ -1984,13 +1984,13 @@
LY_CHECK_ERR_RET(ret, free(when), ret);
*when_p = when;
- struct yin_subelement subelems[3] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_DESCRIPTION, &when->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_REFERENCE, &when->ref, YIN_SUBELEM_UNIQUE},
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
- return yin_parse_content(ctx, subelems, 3, LY_STMT_WHEN, NULL, &when->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_WHEN, NULL, &when->exts);
}
/**
@@ -2007,7 +2007,7 @@
yin_parse_yin_element(struct lys_yin_parser_ctx *ctx, uint16_t *flags, struct lysp_ext_instance **exts)
{
const char *temp_val = NULL;
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
@@ -2025,7 +2025,7 @@
}
FREE_STRING(ctx->xmlctx->ctx, temp_val);
- return yin_parse_content(ctx, subelems, 1, LY_STMT_YIN_ELEMENT, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_YIN_ELEMENT, NULL, exts);
}
/**
@@ -2040,7 +2040,7 @@
static LY_ERR
yin_parse_argument(struct lys_yin_parser_ctx *ctx, struct yin_argument_meta *arg_meta, struct lysp_ext_instance **exts)
{
- struct yin_subelement subelems[2] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_YIN_ELEMENT, arg_meta->flags, YIN_SUBELEM_UNIQUE},
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
@@ -2048,7 +2048,7 @@
LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx));
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, arg_meta->argument, Y_IDENTIF_ARG, LY_STMT_ARGUMENT));
- return yin_parse_content(ctx, subelems, 2, LY_STMT_ARGUMENT, NULL, exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_ARGUMENT, NULL, exts);
}
/**
@@ -2069,7 +2069,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &ex->name, Y_IDENTIF_ARG, LY_STMT_EXTENSION));
struct yin_argument_meta arg_info = {&ex->flags, &ex->argument};
- struct yin_subelement subelems[5] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_ARGUMENT, &arg_info, YIN_SUBELEM_UNIQUE},
{LY_STMT_DESCRIPTION, &ex->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_REFERENCE, &ex->ref, YIN_SUBELEM_UNIQUE},
@@ -2077,7 +2077,7 @@
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
- return yin_parse_content(ctx, subelems, 5, LY_STMT_EXTENSION, NULL, &ex->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_EXTENSION, NULL, &ex->exts);
}
/**
@@ -2101,7 +2101,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &feat->name, Y_IDENTIF_ARG, LY_STMT_FEATURE));
/* parse content */
- struct yin_subelement subelems[5] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_DESCRIPTION, &feat->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_IF_FEATURE, &feat->iffeatures, 0},
{LY_STMT_REFERENCE, &feat->ref, YIN_SUBELEM_UNIQUE},
@@ -2109,7 +2109,7 @@
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- return yin_parse_content(ctx, subelems, 5, LY_STMT_FEATURE, NULL, &feat->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_FEATURE, NULL, &feat->exts);
}
/**
@@ -2133,7 +2133,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &ident->name, Y_IDENTIF_ARG, LY_STMT_IDENTITY));
/* parse content */
- struct yin_subelement subelems[6] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_BASE, &ident->bases, 0},
{LY_STMT_DESCRIPTION, &ident->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_IF_FEATURE, &ident->iffeatures, YIN_SUBELEM_VER2},
@@ -2142,7 +2142,7 @@
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- return yin_parse_content(ctx, subelems, 6, LY_STMT_IDENTITY, NULL, &ident->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_IDENTITY, NULL, &ident->exts);
}
/**
@@ -2159,6 +2159,7 @@
struct lysp_node_list *list;
LY_ERR ret = LY_SUCCESS;
struct yin_subelement *subelems = NULL;
+ size_t subelems_size;
LY_LIST_NEW_RET(ctx->xmlctx->ctx, node_meta->nodes, list, next, LY_EMEM);
list->nodetype = LYS_LIST;
@@ -2169,7 +2170,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &list->name, Y_IDENTIF_ARG, LY_STMT_LIST));
/* parse list content */
- LY_CHECK_RET(subelems_allocator(ctx, 25, (struct lysp_node *)list, &subelems,
+ LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 25, (struct lysp_node *)list, &subelems,
LY_STMT_ACTION, &list->actions, 0,
LY_STMT_ANYDATA, &list->child, 0,
LY_STMT_ANYXML, &list->child, 0,
@@ -2195,8 +2196,8 @@
LY_STMT_USES, &list->child, 0,
LY_STMT_WHEN, &list->when, YIN_SUBELEM_UNIQUE,
LY_STMT_EXTENSION_INSTANCE, NULL, 0));
- ret = yin_parse_content(ctx, subelems, 25, LY_STMT_LIST, NULL, &list->exts);
- subelems_deallocator(25, subelems);
+ ret = yin_parse_content(ctx, subelems, subelems_size, LY_STMT_LIST, NULL, &list->exts);
+ subelems_deallocator(subelems_size, subelems);
LY_CHECK_RET(ret);
/* finalize parent pointers to the reallocated items */
@@ -2225,6 +2226,7 @@
struct lysp_notif **notifs = (struct lysp_notif **)notif_meta->nodes;
LY_ERR ret = LY_SUCCESS;
struct yin_subelement *subelems = NULL;
+ size_t subelems_size;
/* allocate new notification */
LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *notifs, notif, LY_EMEM);
@@ -2236,7 +2238,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, ¬if->name, Y_IDENTIF_ARG, LY_STMT_NOTIFICATION));
/* parse notification content */
- LY_CHECK_RET(subelems_allocator(ctx, 16, (struct lysp_node *)notif, &subelems,
+ LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 16, (struct lysp_node *)notif, &subelems,
LY_STMT_ANYDATA, ¬if->data, 0,
LY_STMT_ANYXML, ¬if->data, 0,
LY_STMT_CHOICE, ¬if->data, 0,
@@ -2254,8 +2256,8 @@
LY_STMT_USES, ¬if->data, 0,
LY_STMT_EXTENSION_INSTANCE, NULL, 0));
- ret = yin_parse_content(ctx, subelems, 16, LY_STMT_NOTIFICATION, NULL, ¬if->exts);
- subelems_deallocator(16, subelems);
+ ret = yin_parse_content(ctx, subelems, subelems_size, LY_STMT_NOTIFICATION, NULL, ¬if->exts);
+ subelems_deallocator(subelems_size, subelems);
LY_CHECK_RET(ret);
/* finalize parent pointers to the reallocated items */
@@ -2279,6 +2281,7 @@
struct lysp_grp **grps = (struct lysp_grp **)gr_meta->nodes;
LY_ERR ret = LY_SUCCESS;
struct yin_subelement *subelems = NULL;
+ size_t subelems_size;
/* create new grouping */
LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *grps, grp, LY_EMEM);
@@ -2290,7 +2293,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &grp->name, Y_IDENTIF_ARG, LY_STMT_GROUPING));
/* parse grouping content */
- LY_CHECK_RET(subelems_allocator(ctx, 16, (struct lysp_node *)grp, &subelems,
+ LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 16, (struct lysp_node *)grp, &subelems,
LY_STMT_ACTION, &grp->actions, 0,
LY_STMT_ANYDATA, &grp->data, 0,
LY_STMT_ANYXML, &grp->data, 0,
@@ -2307,8 +2310,8 @@
LY_STMT_TYPEDEF, &grp->typedefs, 0,
LY_STMT_USES, &grp->data, 0,
LY_STMT_EXTENSION_INSTANCE, NULL, 0));
- ret = yin_parse_content(ctx, subelems, 16, LY_STMT_GROUPING, NULL, &grp->exts);
- subelems_deallocator(16, subelems);
+ ret = yin_parse_content(ctx, subelems, subelems_size, LY_STMT_GROUPING, NULL, &grp->exts);
+ subelems_deallocator(subelems_size, subelems);
LY_CHECK_RET(ret);
/* finalize parent pointers to the reallocated items */
@@ -2331,6 +2334,7 @@
struct lysp_node_container *cont;
LY_ERR ret = LY_SUCCESS;
struct yin_subelement *subelems = NULL;
+ size_t subelems_size;
/* create new container */
LY_LIST_NEW_RET(ctx->xmlctx->ctx, node_meta->nodes, cont, next, LY_EMEM);
@@ -2342,7 +2346,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &cont->name, Y_IDENTIF_ARG, LY_STMT_CONTAINER));
/* parse container content */
- LY_CHECK_RET(subelems_allocator(ctx, 21, (struct lysp_node *)cont, &subelems,
+ LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 21, (struct lysp_node *)cont, &subelems,
LY_STMT_ACTION, &cont->actions, YIN_SUBELEM_VER2,
LY_STMT_ANYDATA, &cont->child, YIN_SUBELEM_VER2,
LY_STMT_ANYXML, &cont->child, 0,
@@ -2364,8 +2368,8 @@
LY_STMT_USES, &cont->child, 0,
LY_STMT_WHEN, &cont->when, YIN_SUBELEM_UNIQUE,
LY_STMT_EXTENSION_INSTANCE, NULL, 0));
- ret = yin_parse_content(ctx, subelems, 21, LY_STMT_CONTAINER, NULL, &cont->exts);
- subelems_deallocator(21, subelems);
+ ret = yin_parse_content(ctx, subelems, subelems_size, LY_STMT_CONTAINER, NULL, &cont->exts);
+ subelems_deallocator(subelems_size, subelems);
LY_CHECK_RET(ret);
LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, cont->groupings, NULL, cont->actions, cont->notifs));
@@ -2387,6 +2391,7 @@
struct lysp_node_case *cas;
LY_ERR ret = LY_SUCCESS;
struct yin_subelement *subelems = NULL;
+ size_t subelems_size;
/* create new case */
LY_LIST_NEW_RET(ctx->xmlctx->ctx, node_meta->nodes, cas, next, LY_EMEM);
@@ -2398,7 +2403,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &cas->name, Y_IDENTIF_ARG, LY_STMT_CASE));
/* parse case content */
- LY_CHECK_RET(subelems_allocator(ctx, 14, (struct lysp_node *)cas, &subelems,
+ LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 14, (struct lysp_node *)cas, &subelems,
LY_STMT_ANYDATA, &cas->child, YIN_SUBELEM_VER2,
LY_STMT_ANYXML, &cas->child, 0,
LY_STMT_CHOICE, &cas->child, 0,
@@ -2413,8 +2418,8 @@
LY_STMT_USES, &cas->child, 0,
LY_STMT_WHEN, &cas->when, YIN_SUBELEM_UNIQUE,
LY_STMT_EXTENSION_INSTANCE, NULL, 0));
- ret = yin_parse_content(ctx, subelems, 14, LY_STMT_CASE, NULL, &cas->exts);
- subelems_deallocator(14, subelems);
+ ret = yin_parse_content(ctx, subelems, subelems_size, LY_STMT_CASE, NULL, &cas->exts);
+ subelems_deallocator(subelems_size, subelems);
return ret;
}
@@ -2433,6 +2438,7 @@
LY_ERR ret = LY_SUCCESS;
struct yin_subelement *subelems = NULL;
struct lysp_node_choice *choice;
+ size_t subelems_size;
/* create new choice */
LY_LIST_NEW_RET(ctx->xmlctx->ctx, node_meta->nodes, choice, next, LY_EMEM);
@@ -2445,7 +2451,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &choice->name, Y_IDENTIF_ARG, LY_STMT_CHOICE));
/* parse choice content */
- LY_CHECK_RET(subelems_allocator(ctx, 17, (struct lysp_node *)choice, &subelems,
+ LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 17, (struct lysp_node *)choice, &subelems,
LY_STMT_ANYDATA, &choice->child, YIN_SUBELEM_VER2,
LY_STMT_ANYXML, &choice->child, 0,
LY_STMT_CASE, &choice->child, 0,
@@ -2463,8 +2469,8 @@
LY_STMT_STATUS, &choice->flags, YIN_SUBELEM_UNIQUE,
LY_STMT_WHEN, &choice->when, YIN_SUBELEM_UNIQUE,
LY_STMT_EXTENSION_INSTANCE, NULL, 0));
- ret = yin_parse_content(ctx, subelems, 17, LY_STMT_CHOICE, NULL, &choice->exts);
- subelems_deallocator(17, subelems);
+ ret = yin_parse_content(ctx, subelems, subelems_size, LY_STMT_CHOICE, NULL, &choice->exts);
+ subelems_deallocator(subelems_size, subelems);
return ret;
}
@@ -2482,6 +2488,7 @@
{
LY_ERR ret = LY_SUCCESS;
struct yin_subelement *subelems = NULL;
+ size_t subelems_size;
/* initiate structure */
inout_meta->inout_p->nodetype = (inout_kw == LY_STMT_INPUT) ? LYS_INPUT : LYS_OUTPUT;
@@ -2492,7 +2499,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NONE, NULL, Y_MAYBE_STR_ARG, inout_kw));
/* parser input/output content */
- LY_CHECK_RET(subelems_allocator(ctx, 12, (struct lysp_node *)inout_meta->inout_p, &subelems,
+ LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 12, (struct lysp_node *)inout_meta->inout_p, &subelems,
LY_STMT_ANYDATA, &inout_meta->inout_p->data, YIN_SUBELEM_VER2,
LY_STMT_ANYXML, &inout_meta->inout_p->data, 0,
LY_STMT_CHOICE, &inout_meta->inout_p->data, 0,
@@ -2505,8 +2512,8 @@
LY_STMT_TYPEDEF, &inout_meta->inout_p->typedefs, 0,
LY_STMT_USES, &inout_meta->inout_p->data, 0,
LY_STMT_EXTENSION_INSTANCE, NULL, 0));
- ret = yin_parse_content(ctx, subelems, 12, inout_kw, NULL, &inout_meta->inout_p->exts);
- subelems_deallocator(12, subelems);
+ ret = yin_parse_content(ctx, subelems, subelems_size, inout_kw, NULL, &inout_meta->inout_p->exts);
+ subelems_deallocator(subelems_size, subelems);
LY_CHECK_RET(ret);
if (!inout_meta->inout_p->data) {
@@ -2534,6 +2541,7 @@
struct lysp_action *act, **acts = (struct lysp_action **)act_meta->nodes;
LY_ERR ret = LY_SUCCESS;
struct yin_subelement *subelems = NULL;
+ size_t subelems_size;
/* create new action */
LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *acts, act, LY_EMEM);
@@ -2545,7 +2553,7 @@
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &act->name, Y_IDENTIF_ARG, LY_STMT_ACTION));
/* parse content */
- LY_CHECK_RET(subelems_allocator(ctx, 9, (struct lysp_node *)act, &subelems,
+ LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 9, (struct lysp_node *)act, &subelems,
LY_STMT_DESCRIPTION, &act->dsc, YIN_SUBELEM_UNIQUE,
LY_STMT_GROUPING, &act->groupings, 0,
LY_STMT_IF_FEATURE, &act->iffeatures, 0,
@@ -2555,8 +2563,8 @@
LY_STMT_STATUS, &act->flags, YIN_SUBELEM_UNIQUE,
LY_STMT_TYPEDEF, &act->typedefs, 0,
LY_STMT_EXTENSION_INSTANCE, NULL, 0));
- ret = (yin_parse_content(ctx, subelems, 9, LY_STMT_ACTION, NULL, &act->exts));
- subelems_deallocator(9, subelems);
+ ret = (yin_parse_content(ctx, subelems, subelems_size, LY_STMT_ACTION, NULL, &act->exts));
+ subelems_deallocator(subelems_size, subelems);
LY_CHECK_RET(ret);
/* always initialize inout, they are technically present (needed for later deviations/refines) */
@@ -2589,6 +2597,7 @@
struct lysp_augment **augs = (struct lysp_augment **)aug_meta->nodes;
LY_ERR ret = LY_SUCCESS;
struct yin_subelement *subelems = NULL;
+ size_t subelems_size;
/* create new augment */
LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *augs, aug, LY_EMEM);
@@ -2601,7 +2610,7 @@
CHECK_NONEMPTY((struct lys_parser_ctx *)ctx, strlen(aug->nodeid), "augment");
/* parser augment content */
- LY_CHECK_RET(subelems_allocator(ctx, 17, (struct lysp_node *)aug, &subelems,
+ LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 17, (struct lysp_node *)aug, &subelems,
LY_STMT_ACTION, &aug->actions, YIN_SUBELEM_VER2,
LY_STMT_ANYDATA, &aug->child, YIN_SUBELEM_VER2,
LY_STMT_ANYXML, &aug->child, 0,
@@ -2619,8 +2628,8 @@
LY_STMT_USES, &aug->child, 0,
LY_STMT_WHEN, &aug->when, YIN_SUBELEM_UNIQUE,
LY_STMT_EXTENSION_INSTANCE, NULL, 0));
- ret = yin_parse_content(ctx, subelems, 17, LY_STMT_AUGMENT, NULL, &aug->exts);
- subelems_deallocator(17, subelems);
+ ret = yin_parse_content(ctx, subelems, subelems_size, LY_STMT_AUGMENT, NULL, &aug->exts);
+ subelems_deallocator(subelems_size, subelems);
LY_CHECK_RET(ret);
LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, NULL, NULL, aug->actions, aug->notifs));
@@ -2670,10 +2679,10 @@
if (dev_mod == LYS_DEV_NOT_SUPPORTED) {
d = calloc(1, sizeof *d);
LY_CHECK_ERR_RET(!d, LOGMEM(ctx->xmlctx->ctx), LY_EMEM);
- struct yin_subelement subelems[1] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_EXTENSION_INSTANCE, NULL, 0}
};
- ret = yin_parse_content(ctx, subelems, 1, LY_STMT_DEVIATE, NULL, &d->exts);
+ ret = yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_DEVIATE, NULL, &d->exts);
} else if (dev_mod == LYS_DEV_ADD) {
d_add = calloc(1, sizeof *d_add);
@@ -2681,7 +2690,7 @@
d = (struct lysp_deviate *)d_add;
struct minmax_dev_meta min = {&d_add->min, &d_add->flags, &d_add->exts};
struct minmax_dev_meta max = {&d_add->max, &d_add->flags, &d_add->exts};
- struct yin_subelement subelems[9] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_CONFIG, &d_add->flags, YIN_SUBELEM_UNIQUE},
{LY_STMT_DEFAULT, &d_add->dflts, 0},
{LY_STMT_MANDATORY, &d_add->flags, YIN_SUBELEM_UNIQUE},
@@ -2692,7 +2701,7 @@
{LY_STMT_UNITS, &d_add->units, YIN_SUBELEM_UNIQUE},
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- ret = yin_parse_content(ctx, subelems, 9, LY_STMT_DEVIATE, NULL, &d_add->exts);
+ ret = yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_DEVIATE, NULL, &d_add->exts);
} else if (dev_mod == LYS_DEV_REPLACE) {
d_rpl = calloc(1, sizeof *d_rpl);
@@ -2700,7 +2709,7 @@
d = (struct lysp_deviate *)d_rpl;
struct minmax_dev_meta min = {&d_rpl->min, &d_rpl->flags, &d_rpl->exts};
struct minmax_dev_meta max = {&d_rpl->max, &d_rpl->flags, &d_rpl->exts};
- struct yin_subelement subelems[8] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_CONFIG, &d_rpl->flags, YIN_SUBELEM_UNIQUE},
{LY_STMT_DEFAULT, &d_rpl->dflt, YIN_SUBELEM_UNIQUE},
{LY_STMT_MANDATORY, &d_rpl->flags, YIN_SUBELEM_UNIQUE},
@@ -2710,20 +2719,20 @@
{LY_STMT_UNITS, &d_rpl->units, YIN_SUBELEM_UNIQUE},
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- ret = yin_parse_content(ctx, subelems, 8, LY_STMT_DEVIATE, NULL, &d_rpl->exts);
+ ret = yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_DEVIATE, NULL, &d_rpl->exts);
} else {
d_del = calloc(1, sizeof *d_del);
LY_CHECK_ERR_RET(!d_del, LOGMEM(ctx->xmlctx->ctx), LY_EMEM);
d = (struct lysp_deviate *)d_del;
- struct yin_subelement subelems[5] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_DEFAULT, &d_del->dflts, 0},
{LY_STMT_MUST, &d_del->musts, 0},
{LY_STMT_UNIQUE, &d_del->uniques, 0},
{LY_STMT_UNITS, &d_del->units, YIN_SUBELEM_UNIQUE},
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- ret = yin_parse_content(ctx, subelems, 5, LY_STMT_DEVIATE, NULL, &d_del->exts);
+ ret = yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_DEVIATE, NULL, &d_del->exts);
}
LY_CHECK_GOTO(ret, cleanup);
@@ -2758,14 +2767,14 @@
LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx));
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_TARGET_NODE, &dev->nodeid, Y_STR_ARG, LY_STMT_DEVIATION));
CHECK_NONEMPTY((struct lys_parser_ctx *)ctx, strlen(dev->nodeid), "deviation");
- struct yin_subelement subelems[4] = {
+ struct yin_subelement subelems[] = {
{LY_STMT_DESCRIPTION, &dev->dsc, YIN_SUBELEM_UNIQUE},
{LY_STMT_DEVIATE, &dev->deviates, YIN_SUBELEM_MANDATORY},
{LY_STMT_REFERENCE, &dev->ref, YIN_SUBELEM_UNIQUE},
{LY_STMT_EXTENSION_INSTANCE, NULL, 0},
};
- return yin_parse_content(ctx, subelems, 4, LY_STMT_DEVIATION, NULL, &dev->exts);
+ return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), LY_STMT_DEVIATION, NULL, &dev->exts);
}
/**
@@ -3644,12 +3653,13 @@
LY_ERR ret = LY_SUCCESS;
struct yin_subelement *subelems = NULL;
struct lysp_submodule *dup;
+ size_t subelems_size;
mod->is_submod = 0;
LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx));
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &mod->mod->name, Y_IDENTIF_ARG, LY_STMT_MODULE));
- LY_CHECK_RET(subelems_allocator(ctx, 28, NULL, &subelems,
+ LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 28, NULL, &subelems,
LY_STMT_ANYDATA, &mod->data, YIN_SUBELEM_VER2,
LY_STMT_ANYXML, &mod->data, 0,
LY_STMT_AUGMENT, &mod->augments, 0,
@@ -3679,8 +3689,8 @@
LY_STMT_YANG_VERSION, &mod->version, YIN_SUBELEM_UNIQUE,
LY_STMT_EXTENSION_INSTANCE, NULL, 0));
- ret = yin_parse_content(ctx, subelems, 28, LY_STMT_MODULE, NULL, &mod->exts);
- subelems_deallocator(28, subelems);
+ ret = yin_parse_content(ctx, subelems, subelems_size, LY_STMT_MODULE, NULL, &mod->exts);
+ subelems_deallocator(subelems_size, subelems);
LY_CHECK_RET(ret);
/* finalize parent pointers to the reallocated items */
@@ -3712,12 +3722,13 @@
LY_ERR ret = LY_SUCCESS;
struct yin_subelement *subelems = NULL;
struct lysp_submodule *dup;
+ size_t subelems_size;
submod->is_submod = 1;
LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx));
LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &submod->name, Y_IDENTIF_ARG, LY_STMT_SUBMODULE));
- LY_CHECK_RET(subelems_allocator(ctx, 27, NULL, &subelems,
+ LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 27, NULL, &subelems,
LY_STMT_ANYDATA, &submod->data, YIN_SUBELEM_VER2,
LY_STMT_ANYXML, &submod->data, 0,
LY_STMT_AUGMENT, &submod->augments, 0,
@@ -3746,8 +3757,8 @@
LY_STMT_YANG_VERSION, &submod->version, YIN_SUBELEM_UNIQUE,
LY_STMT_EXTENSION_INSTANCE, NULL, 0));
- ret = yin_parse_content(ctx, subelems, 27, LY_STMT_SUBMODULE, NULL, &submod->exts);
- subelems_deallocator(27, subelems);
+ ret = yin_parse_content(ctx, subelems, subelems_size, LY_STMT_SUBMODULE, NULL, &submod->exts);
+ subelems_deallocator(subelems_size, subelems);
LY_CHECK_RET(ret);
/* finalize parent pointers to the reallocated items */
diff --git a/src/path.c b/src/path.c
index e565dfe..f51bee7 100644
--- a/src/path.c
+++ b/src/path.c
@@ -170,7 +170,8 @@
/* FuncName */
LY_CHECK_GOTO(lyxp_check_token(ctx, exp, *tok_idx, LYXP_TOKEN_FUNCNAME), token_error);
- if ((exp->tok_len[*tok_idx] != 7) || strncmp(exp->expr + exp->tok_pos[*tok_idx], "current", 7)) {
+ if ((exp->tok_len[*tok_idx] != ly_strlen_const("current")) ||
+ strncmp(exp->expr + exp->tok_pos[*tok_idx], "current", ly_strlen_const("current"))) {
LOGVAL_P(ctx, cur_node, LYVE_XPATH, "Invalid function \"%.*s\" invocation in path.",
exp->tok_len[*tok_idx], exp->expr + exp->tok_pos[*tok_idx]);
goto token_error;
@@ -582,7 +583,7 @@
LY_ARRAY_NEW_RET(ctx, *predicates, p, LY_EMEM);
/* syntax was already checked */
- p->position = strtoull(expr->expr + expr->tok_pos[*tok_idx], (char **)&name, 10);
+ p->position = strtoull(expr->expr + expr->tok_pos[*tok_idx], (char **)&name, LY_BASE_DEC);
++(*tok_idx);
/* ']' */
diff --git a/src/plugins_exts.c b/src/plugins_exts.c
index 2bf6889..1b74d80 100644
--- a/src/plugins_exts.c
+++ b/src/plugins_exts.c
@@ -24,7 +24,7 @@
/**
* @brief list of all extension plugins implemented internally
*/
-struct lyext_plugins_list lyext_plugins_internal[6] = {
+struct lyext_plugins_list lyext_plugins_internal[] = {
{"ietf-netconf-acm", "2012-02-22", "default-deny-write", &nacm_plugin},
{"ietf-netconf-acm", "2018-02-14", "default-deny-write", &nacm_plugin},
{"ietf-netconf-acm", "2012-02-22", "default-deny-all", &nacm_plugin},
diff --git a/src/plugins_exts_metadata.c b/src/plugins_exts_metadata.c
index ceae257..03d6c03 100644
--- a/src/plugins_exts_metadata.c
+++ b/src/plugins_exts_metadata.c
@@ -26,7 +26,14 @@
LYEXT_VERSION_CHECK
*/
-struct lysc_ext_substmt annotation_substmt[7] = {
+#define ANNOTATION_SUBSTMT_IFF 0
+#define ANNOTATION_SUBSTMT_UNITS 1
+#define ANNOTATION_SUBSTMT_STATUS 2
+#define ANNOTATION_SUBSTMT_TYPE 3
+#define ANNOTATION_SUBSTMT_DSC 4
+#define ANNOTATION_SUBSTMT_REF 5
+
+struct lysc_ext_substmt annotation_substmt[] = {
{LY_STMT_IF_FEATURE, LY_STMT_CARD_ANY, NULL},
{LY_STMT_UNITS, LY_STMT_CARD_OPT, NULL},
{LY_STMT_STATUS, LY_STMT_CARD_OPT, NULL},
@@ -75,10 +82,10 @@
/* compile annotation substatements */
c_ext->data = annotation = calloc(1, sizeof *annotation);
LY_CHECK_ERR_RET(!annotation, LOGMEM(cctx->ctx), LY_EMEM);
- annotation_substmt[0].storage = &annotation->iffeatures;
- annotation_substmt[1].storage = &annotation->units;
- annotation_substmt[2].storage = &annotation->flags;
- annotation_substmt[3].storage = &annotation->type;
+ annotation_substmt[ANNOTATION_SUBSTMT_IFF].storage = &annotation->iffeatures;
+ annotation_substmt[ANNOTATION_SUBSTMT_UNITS].storage = &annotation->units;
+ annotation_substmt[ANNOTATION_SUBSTMT_STATUS].storage = &annotation->flags;
+ annotation_substmt[ANNOTATION_SUBSTMT_TYPE].storage = &annotation->type;
/* description and reference are allowed, but not compiled */
LY_CHECK_RET(lys_compile_extension_instance(cctx, p_ext, annotation_substmt));
@@ -100,10 +107,10 @@
struct lyext_metadata *annotation = (struct lyext_metadata *)ext->data;
- annotation_substmt[0].storage = &annotation->iffeatures;
- annotation_substmt[1].storage = &annotation->units;
- annotation_substmt[2].storage = &annotation->flags;
- annotation_substmt[3].storage = &annotation->type;
+ annotation_substmt[ANNOTATION_SUBSTMT_IFF].storage = &annotation->iffeatures;
+ annotation_substmt[ANNOTATION_SUBSTMT_UNITS].storage = &annotation->units;
+ annotation_substmt[ANNOTATION_SUBSTMT_STATUS].storage = &annotation->flags;
+ annotation_substmt[ANNOTATION_SUBSTMT_TYPE].storage = &annotation->type;
lysc_extension_instance_free(ctx, annotation_substmt);
free(ext->data);
diff --git a/src/plugins_types.c b/src/plugins_types.c
index fb52014..ebdaec6 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -468,7 +468,8 @@
memset(&valcopy[len], '0', fraction_digits);
}
- rc = ly_type_parse_int("decimal64", 10, INT64_C(-9223372036854775807) - INT64_C(1), INT64_C(9223372036854775807), valcopy, len, &d, err);
+ rc = ly_type_parse_int("decimal64", LY_BASE_DEC, INT64_C(-9223372036854775807) - INT64_C(1), INT64_C(9223372036854775807),
+ valcopy, len, &d, err);
if (!rc && ret) {
*ret = d;
}
@@ -512,8 +513,9 @@
goto cleanup;
} else if (rc < 0) {
/* error */
- PCRE2_UCHAR pcre2_errmsg[256] = {0};
- pcre2_get_error_message(rc, pcre2_errmsg, 256);
+ PCRE2_UCHAR pcre2_errmsg[LY_PCRE2_MSG_LIMIT] = {0};
+ pcre2_get_error_message(rc, pcre2_errmsg, LY_PCRE2_MSG_LIMIT);
+
*err = ly_err_new(LY_LLERR, LY_ESYS, 0, strdup((const char *)pcre2_errmsg), NULL, NULL);
ret = LY_ESYS;
goto cleanup;
@@ -639,11 +641,11 @@
/* set allowed base */
switch (hints & (LYD_VALHINT_DECNUM | LYD_VALHINT_OCTNUM | LYD_VALHINT_HEXNUM)) {
case LYD_VALHINT_DECNUM:
- return 10;
+ return LY_BASE_DEC;
case LYD_VALHINT_OCTNUM:
- return 8;
+ return LY_BASE_OCT;
case LYD_VALHINT_HEXNUM:
- return 16;
+ return LY_BASE_HEX;
default:
break;
}
@@ -848,7 +850,7 @@
{
int64_t d;
struct lysc_type_dec *type_dec = (struct lysc_type_dec *)type;
- char buf[22];
+ char buf[LY_NUMBER_MAXLEN];
if (!value || !value[0] || !value_len) {
*err = ly_err_new(LY_LLERR, LY_EVALID, LYVE_DATA, strdup("Invalid empty decimal64 value."), NULL, NULL);
@@ -974,9 +976,10 @@
/* length of the encoded string */
if (type_bin->length) {
- char buf[22];
+ char buf[LY_NUMBER_MAXLEN];
+ /* get correct length based on base64 encoding rules */
uint64_t len = ((count / 4) * 3) - termination;
- snprintf(buf, 22, "%" PRIu64, len);
+ snprintf(buf, LY_NUMBER_MAXLEN, "%" PRIu64, len);
LY_CHECK_RET(ly_type_validate_range(LY_TYPE_BINARY, type_bin->length, len, buf, err));
}
@@ -1022,11 +1025,11 @@
/* length restriction of the string */
if (type_str->length) {
- char buf[22];
+ char buf[LY_NUMBER_MAXLEN];
size_t char_count = ly_utf8len(value, value_len);
/* value_len is in bytes, but we need number of chaarcters here */
- snprintf(buf, 22, "%lu", char_count);
+ snprintf(buf, LY_NUMBER_MAXLEN, "%zu", char_count);
LY_CHECK_RET(ly_type_validate_range(LY_TYPE_BINARY, type_str->length, char_count, buf, err));
}
@@ -1293,9 +1296,9 @@
/* check hints */
LY_CHECK_RET(type_check_hints(hints, value, value_len, type->basetype, NULL, err));
- if ((value_len == 4) && !strncmp(value, "true", 4)) {
+ if ((value_len == ly_strlen_const("true")) && !strncmp(value, "true", ly_strlen_const("true"))) {
i = 1;
- } else if ((value_len == 5) && !strncmp(value, "false", 5)) {
+ } else if ((value_len == ly_strlen_const("false")) && !strncmp(value, "false", ly_strlen_const("false"))) {
i = 0;
} else {
char *errmsg;
diff --git a/src/printer_internal.h b/src/printer_internal.h
index d1909f8..c648809 100644
--- a/src/printer_internal.h
+++ b/src/printer_internal.h
@@ -56,6 +56,8 @@
#define LEVEL_INC LEVEL++ /**< increase indentation level */
#define LEVEL_DEC LEVEL-- /**< decrease indentation level */
+#define XML_NS_INDENT 8
+
/**
* @brief YANG printer of the parsed submodule. Full YANG printer.
*
diff --git a/src/printer_lyb.c b/src/printer_lyb.c
index 12da019..01d35f4 100644
--- a/src/printer_lyb.c
+++ b/src/printer_lyb.c
@@ -267,8 +267,8 @@
if (full) {
/* write the meta information (inner chunk count and chunk size) */
- meta_buf[0] = full->written & 0xFF;
- meta_buf[1] = full->inner_chunks & 0xFF;
+ meta_buf[0] = full->written & LYB_BYTE_MASK;
+ meta_buf[1] = full->inner_chunks & LYB_BYTE_MASK;
LY_CHECK_RET(ly_write_skipped(out, full->position, (char *)meta_buf, LYB_META_BYTES));
/* zero written and inner chunks */
@@ -305,8 +305,8 @@
uint8_t meta_buf[LYB_META_BYTES];
/* write the meta chunk information */
- meta_buf[0] = LYB_LAST_SUBTREE(lybctx).written & 0xFF;
- meta_buf[1] = LYB_LAST_SUBTREE(lybctx).inner_chunks & 0xFF;
+ meta_buf[0] = LYB_LAST_SUBTREE(lybctx).written & LYB_BYTE_MASK;
+ meta_buf[1] = LYB_LAST_SUBTREE(lybctx).inner_chunks & LYB_BYTE_MASK;
LY_CHECK_RET(ly_write_skipped(out, LYB_LAST_SUBTREE(lybctx).position, (char *)&meta_buf, LYB_META_BYTES));
LY_ARRAY_DECREMENT(lybctx->subtrees);
@@ -432,17 +432,17 @@
revision = 0;
if (mod && mod->revision) {
int r = atoi(mod->revision);
- r -= 2000;
- r <<= 9;
+ r -= LYB_REV_YEAR_OFFSET;
+ r <<= LYB_REV_YEAR_SHIFT;
revision |= r;
- r = atoi(mod->revision + 5);
- r <<= 5;
+ r = atoi(mod->revision + ly_strlen_const("YYYY-"));
+ r <<= LYB_REV_MONTH_SHIFT;
revision |= r;
- r = atoi(mod->revision + 8);
+ r = atoi(mod->revision + ly_strlen_const("YYYY-MM-"));
revision |= r;
}
@@ -514,12 +514,8 @@
static LY_ERR
lyb_print_magic_number(struct ly_out *out)
{
- char magic_number[3];
-
/* 'l', 'y', 'b' - 0x6c7962 */
- magic_number[0] = 'l';
- magic_number[1] = 'y';
- magic_number[2] = 'b';
+ char magic_number[] = {'l', 'y', 'b'};
LY_CHECK_RET(ly_write_(out, magic_number, 3));
diff --git a/src/printer_yang.c b/src/printer_yang.c
index 0aeb6d5..4afc83d 100644
--- a/src/printer_yang.c
+++ b/src/printer_yang.c
@@ -582,12 +582,14 @@
ypr_open(ctx->out, flag);
ly_print_(ctx->out, "%*s%s \"", INDENT, name);
- ypr_encode(ctx->out, (restr->arg.str[0] != 0x15 && restr->arg.str[0] != 0x06) ? restr->arg.str : &restr->arg.str[1], -1);
+ ypr_encode(ctx->out,
+ (restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK && restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK) ?
+ restr->arg.str : &restr->arg.str[1], -1);
ly_print_(ctx->out, "\"");
LEVEL++;
yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, restr->exts, &inner_flag, 0);
- if (restr->arg.str[0] == 0x15) {
+ if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
/* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
ypr_open(ctx->out, &inner_flag);
ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", restr->exts);
diff --git a/src/printer_yin.c b/src/printer_yin.c
index 91309cb..26a9eb6 100644
--- a/src/printer_yin.c
+++ b/src/printer_yin.c
@@ -338,12 +338,14 @@
}
ly_print_(ctx->out, "%*s<%s %s=\"", INDENT, name, attr);
- lyxml_dump_text(ctx->out, (restr->arg.str[0] != 0x15 && restr->arg.str[0] != 0x06) ? restr->arg.str : &restr->arg.str[1], 1);
+ lyxml_dump_text(ctx->out,
+ (restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK && restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK) ?
+ restr->arg.str : &restr->arg.str[1], 1);
ly_print_(ctx->out, "\"");
LEVEL++;
yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, restr->exts, &inner_flag, 0);
- if (restr->arg.str[0] == 0x15) {
+ if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
ypr_close_parent(ctx, &inner_flag);
/* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", restr->exts);
@@ -1465,8 +1467,8 @@
ly_print_(ctx->out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
ly_print_(ctx->out, "%*s<module name=\"%s\"\n", INDENT, module->name);
- ypr_xmlns(ctx, module, 8);
- ypr_import_xmlns(ctx, modp, 8);
+ ypr_xmlns(ctx, module, XML_NS_INDENT);
+ ypr_import_xmlns(ctx, modp, XML_NS_INDENT);
ly_print_(ctx->out, ">\n");
LEVEL++;
@@ -1527,8 +1529,8 @@
ly_print_(ctx->out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
ly_print_(ctx->out, "%*s<submodule name=\"%s\"\n", INDENT, submodp->name);
- ypr_xmlns(ctx, module, 8);
- ypr_import_xmlns(ctx, (struct lysp_module *)submodp, 8);
+ ypr_xmlns(ctx, module, XML_NS_INDENT);
+ ypr_import_xmlns(ctx, (struct lysp_module *)submodp, XML_NS_INDENT);
ly_print_(ctx->out, ">\n");
LEVEL++;
diff --git a/src/schema_compile.c b/src/schema_compile.c
index 2d4e8a9..d2efc50 100644
--- a/src/schema_compile.c
+++ b/src/schema_compile.c
@@ -768,15 +768,15 @@
for (i = 0; i < set->used; ++i) {
xp_scnode = &set->val.scnodes[i];
- if (xp_scnode->in_ctx != -1) {
+ if (xp_scnode->in_ctx != LYXP_SET_SCNODE_START_USED) {
/* check node when, skip the context node (it was just checked) */
- xp_scnode->in_ctx = 1;
+ xp_scnode->in_ctx = LYXP_SET_SCNODE_ATOM_CTX;
}
}
for (i = 0; i < set->used; ++i) {
xp_scnode = &set->val.scnodes[i];
- if (xp_scnode->in_ctx != 1) {
+ if (xp_scnode->in_ctx != LYXP_SET_SCNODE_ATOM_CTX) {
/* already checked */
continue;
}
@@ -784,7 +784,7 @@
if ((xp_scnode->type != LYXP_NODE_ELEM) || (xp_scnode->scnode->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF)) ||
!xp_scnode->scnode->when) {
/* no when to check */
- xp_scnode->in_ctx = 0;
+ xp_scnode->in_ctx = LYXP_SET_SCNODE_ATOM;
continue;
}
@@ -804,17 +804,18 @@
if (tmp_set.val.scnodes[j].type == LYXP_NODE_ELEM) {
/* try to find this node in our set */
uint32_t idx;
- if (lyxp_set_scnode_contains(set, tmp_set.val.scnodes[j].scnode, LYXP_NODE_ELEM, -1, &idx) && (set->val.scnodes[idx].in_ctx == -1)) {
+ if (lyxp_set_scnode_contains(set, tmp_set.val.scnodes[j].scnode, LYXP_NODE_ELEM, -1, &idx) &&
+ (set->val.scnodes[idx].in_ctx == LYXP_SET_SCNODE_START_USED)) {
LOGVAL(set->ctx, LY_VLOG_LYSC, node, LY_VCODE_CIRC_WHEN, node->name, set->val.scnodes[idx].scnode->name);
ret = LY_EVALID;
goto cleanup;
}
/* needs to be checked, if in both sets, will be ignored */
- tmp_set.val.scnodes[j].in_ctx = 1;
+ tmp_set.val.scnodes[j].in_ctx = LYXP_SET_SCNODE_ATOM_CTX;
} else {
/* no when, nothing to check */
- tmp_set.val.scnodes[j].in_ctx = 0;
+ tmp_set.val.scnodes[j].in_ctx = LYXP_SET_SCNODE_ATOM;
}
}
@@ -827,7 +828,7 @@
} while (node && (node->nodetype & (LYS_CASE | LYS_CHOICE)));
/* this node when was checked (xp_scnode could have been reallocd) */
- set->val.scnodes[i].in_ctx = -1;
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_START_USED;
}
cleanup:
@@ -997,7 +998,7 @@
lysc_path((struct lysc_node *)node, LYSC_PATH_LOG, ctx->path, LYSC_CTX_BUFSIZE);
for (i = 0; i < tmp_set.used; ++i) {
/* skip roots'n'stuff */
- if ((tmp_set.val.scnodes[i].type == LYXP_NODE_ELEM) && (tmp_set.val.scnodes[i].in_ctx != -1)) {
+ if ((tmp_set.val.scnodes[i].type == LYXP_NODE_ELEM) && (tmp_set.val.scnodes[i].in_ctx != LYXP_SET_SCNODE_START_USED)) {
struct lysc_node *schema = tmp_set.val.scnodes[i].scnode;
/* XPath expression cannot reference "lower" status than the node that has the definition */
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index e3862c4..49c376c 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -469,7 +469,7 @@
switch (basetype) {
case LY_TYPE_INT8: /* range */
if (valcopy) {
- ret = ly_parse_int(valcopy, strlen(valcopy), INT64_C(-128), INT64_C(127), 10, max ? &part->max_64 : &part->min_64);
+ ret = ly_parse_int(valcopy, strlen(valcopy), INT64_C(-128), INT64_C(127), LY_BASE_DEC, max ? &part->max_64 : &part->min_64);
} else if (max) {
part->max_64 = INT64_C(127);
} else {
@@ -481,7 +481,8 @@
break;
case LY_TYPE_INT16: /* range */
if (valcopy) {
- ret = ly_parse_int(valcopy, strlen(valcopy), INT64_C(-32768), INT64_C(32767), 10, max ? &part->max_64 : &part->min_64);
+ ret = ly_parse_int(valcopy, strlen(valcopy), INT64_C(-32768), INT64_C(32767), LY_BASE_DEC,
+ max ? &part->max_64 : &part->min_64);
} else if (max) {
part->max_64 = INT64_C(32767);
} else {
@@ -493,7 +494,8 @@
break;
case LY_TYPE_INT32: /* range */
if (valcopy) {
- ret = ly_parse_int(valcopy, strlen(valcopy), INT64_C(-2147483648), INT64_C(2147483647), 10, max ? &part->max_64 : &part->min_64);
+ ret = ly_parse_int(valcopy, strlen(valcopy), INT64_C(-2147483648), INT64_C(2147483647), LY_BASE_DEC,
+ max ? &part->max_64 : &part->min_64);
} else if (max) {
part->max_64 = INT64_C(2147483647);
} else {
@@ -506,8 +508,8 @@
case LY_TYPE_INT64: /* range */
case LY_TYPE_DEC64: /* range */
if (valcopy) {
- ret = ly_parse_int(valcopy, strlen(valcopy), INT64_C(-9223372036854775807) - INT64_C(1), INT64_C(9223372036854775807), 10,
- max ? &part->max_64 : &part->min_64);
+ ret = ly_parse_int(valcopy, strlen(valcopy), INT64_C(-9223372036854775807) - INT64_C(1), INT64_C(9223372036854775807),
+ LY_BASE_DEC, max ? &part->max_64 : &part->min_64);
} else if (max) {
part->max_64 = INT64_C(9223372036854775807);
} else {
@@ -519,7 +521,7 @@
break;
case LY_TYPE_UINT8: /* range */
if (valcopy) {
- ret = ly_parse_uint(valcopy, strlen(valcopy), UINT64_C(255), 10, max ? &part->max_u64 : &part->min_u64);
+ ret = ly_parse_uint(valcopy, strlen(valcopy), UINT64_C(255), LY_BASE_DEC, max ? &part->max_u64 : &part->min_u64);
} else if (max) {
part->max_u64 = UINT64_C(255);
} else {
@@ -531,7 +533,7 @@
break;
case LY_TYPE_UINT16: /* range */
if (valcopy) {
- ret = ly_parse_uint(valcopy, strlen(valcopy), UINT64_C(65535), 10, max ? &part->max_u64 : &part->min_u64);
+ ret = ly_parse_uint(valcopy, strlen(valcopy), UINT64_C(65535), LY_BASE_DEC, max ? &part->max_u64 : &part->min_u64);
} else if (max) {
part->max_u64 = UINT64_C(65535);
} else {
@@ -543,7 +545,8 @@
break;
case LY_TYPE_UINT32: /* range */
if (valcopy) {
- ret = ly_parse_uint(valcopy, strlen(valcopy), UINT64_C(4294967295), 10, max ? &part->max_u64 : &part->min_u64);
+ ret = ly_parse_uint(valcopy, strlen(valcopy), UINT64_C(4294967295), LY_BASE_DEC,
+ max ? &part->max_u64 : &part->min_u64);
} else if (max) {
part->max_u64 = UINT64_C(4294967295);
} else {
@@ -557,7 +560,8 @@
case LY_TYPE_STRING: /* length */
case LY_TYPE_BINARY: /* length */
if (valcopy) {
- ret = ly_parse_uint(valcopy, strlen(valcopy), UINT64_C(18446744073709551615), 10, max ? &part->max_u64 : &part->min_u64);
+ ret = ly_parse_uint(valcopy, strlen(valcopy), UINT64_C(18446744073709551615), LY_BASE_DEC,
+ max ? &part->max_u64 : &part->min_u64);
} else if (max) {
part->max_u64 = UINT64_C(18446744073709551615);
} else {
@@ -636,7 +640,7 @@
}
parts_done++;
break;
- } else if (!strncmp(expr, "min", 3)) {
+ } else if (!strncmp(expr, "min", ly_strlen_const("min"))) {
if (parts) {
/* min cannot be used elsewhere than in the first part */
LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_SYNTAX_YANG,
@@ -644,7 +648,7 @@
expr - range_p->arg.str, range_p->arg.str);
goto cleanup;
}
- expr += 3;
+ expr += ly_strlen_const("min");
LY_ARRAY_NEW_GOTO(ctx->ctx, parts, part, ret, cleanup);
LY_CHECK_GOTO(range_part_minmax(ctx, part, 0, 0, basetype, 1, length_restr, frdigits, base_range, NULL), cleanup);
@@ -684,8 +688,8 @@
}
/* continue with possible another expression part */
- } else if (!strncmp(expr, "max", 3)) {
- expr += 3;
+ } else if (!strncmp(expr, "max", ly_strlen_const("max"))) {
+ expr += ly_strlen_const("max");
while (isspace(*expr)) {
expr++;
}
@@ -1006,7 +1010,8 @@
/* find our range */
for (idx = 0; ublock2urange[idx][0]; ++idx) {
- if (!strncmp(perl_regex + start + 5, ublock2urange[idx][0], strlen(ublock2urange[idx][0]))) {
+ if (!strncmp(perl_regex + start + ly_strlen_const("\\p{Is"),
+ ublock2urange[idx][0], strlen(ublock2urange[idx][0]))) {
break;
}
}
@@ -1041,8 +1046,8 @@
PCRE2_UTF | PCRE2_ANCHORED | PCRE2_ENDANCHORED | PCRE2_DOLLAR_ENDONLY | PCRE2_NO_AUTO_CAPTURE,
&err_code, &err_offset, NULL);
if (!code_local) {
- PCRE2_UCHAR err_msg[256] = {0};
- pcre2_get_error_message(err_code, err_msg, 256);
+ PCRE2_UCHAR err_msg[LY_PCRE2_MSG_LIMIT] = {0};
+ pcre2_get_error_message(err_code, err_msg, LY_PCRE2_MSG_LIMIT);
LOGVAL(ctx, LY_VLOG_STR, log_path, LY_VCODE_INREGEXP, pattern, perl_regex + err_offset, err_msg);
free(perl_regex);
return LY_EVALID;
@@ -1091,7 +1096,7 @@
ret = lys_compile_type_pattern_check(ctx->ctx, ctx->path, &patterns_p[u].arg.str[1], &(*pattern)->code);
LY_CHECK_RET(ret);
- if (patterns_p[u].arg.str[0] == 0x15) {
+ if (patterns_p[u].arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
(*pattern)->inverted = 1;
}
DUP_STRING_GOTO(ctx->ctx, &patterns_p[u].arg.str[1], (*pattern)->expr, ret, done);
@@ -1918,6 +1923,11 @@
}
/**
+ * @brief Special bits combination marking the uses_status value and propagated by ::lys_compile_uses() function.
+ */
+#define LYS_STATUS_USES LYS_CONFIG_MASK
+
+/**
* @brief Compile status information of the given node.
*
* To simplify getting status of the node, the flags are set following inheritance rules, so all the nodes
@@ -1937,9 +1947,9 @@
* current in deprecated or deprecated in obsolete, so we do print warning and inherit status */
if (!((*node_flags) & LYS_STATUS_MASK)) {
if (parent_flags & (LYS_STATUS_DEPRC | LYS_STATUS_OBSLT)) {
- if ((parent_flags & 0x3) != 0x3) {
+ if ((parent_flags & LYS_STATUS_USES) != LYS_STATUS_USES) {
/* do not print the warning when inheriting status from uses - the uses_status value has a special
- * combination of bits (0x3) which marks the uses_status value */
+ * combination of bits (LYS_STATUS_USES) which marks the uses_status value */
LOGWRN(ctx->ctx, "Missing explicit \"%s\" status that was already specified in parent, inheriting.",
(parent_flags & LYS_STATUS_DEPRC) ? "deprecated" : "obsolete");
}
@@ -3376,8 +3386,8 @@
/* compile data nodes */
LY_LIST_FOR(grp->data, pnode) {
- /* 0x3 in uses_status is a special bits combination to be able to detect status flags from uses */
- ret = lys_compile_node(ctx, pnode, parent, (uses_p->flags & LYS_STATUS_MASK) | 0x3, &uses_child_set);
+ /* LYS_STATUS_USES in uses_status is a special bits combination to be able to detect status flags from uses */
+ ret = lys_compile_node(ctx, pnode, parent, (uses_p->flags & LYS_STATUS_MASK) | LYS_STATUS_USES, &uses_child_set);
LY_CHECK_GOTO(ret, cleanup);
}
diff --git a/src/schema_features.c b/src/schema_features.c
index 303ee51..9de35ca 100644
--- a/src/schema_features.c
+++ b/src/schema_features.c
@@ -31,15 +31,19 @@
#include "tree_schema.h"
#include "tree_schema_internal.h"
+#define IFF_RECORDS_IN_BYTE 4
+#define IFF_RECORD_BITS 2
+#define IFF_RECORD_MASK 0x3
+
uint8_t
lysc_iff_getop(uint8_t *list, size_t pos)
{
uint8_t *item;
- uint8_t mask = 3, result;
+ uint8_t mask = IFF_RECORD_MASK, result;
- item = &list[pos / 4];
- result = (*item) & (mask << 2 * (pos % 4));
- return result >> 2 * (pos % 4);
+ item = &list[pos / IFF_RECORDS_IN_BYTE];
+ result = (*item) & (mask << IFF_RECORD_BITS * (pos % IFF_RECORDS_IN_BYTE));
+ return result >> IFF_RECORD_BITS * (pos % IFF_RECORDS_IN_BYTE);
}
static LY_ERR
@@ -186,6 +190,7 @@
size_t index; /**< first empty item */
uint8_t *stack; /**< stack - array of @ref ifftokens to create the if-feature expression in prefix format */
};
+#define IFF_STACK_SIZE_STEP 4
/**
* @brief Add @ref ifftokens into the stack.
@@ -198,7 +203,7 @@
iff_stack_push(struct iff_stack *stack, uint8_t value)
{
if (stack->index == stack->size) {
- stack->size += 4;
+ stack->size += IFF_STACK_SIZE_STEP;
stack->stack = ly_realloc(stack->stack, stack->size * sizeof *stack->stack);
LY_CHECK_ERR_RET(!stack->stack, LOGMEM(NULL); stack->size = 0, LY_EMEM);
}
@@ -242,14 +247,14 @@
iff_setop(uint8_t *list, uint8_t op, size_t pos)
{
uint8_t *item;
- uint8_t mask = 3;
+ uint8_t mask = IFF_RECORD_MASK;
- assert(op <= 3); /* max 2 bits */
+ assert(op <= IFF_RECORD_MASK); /* max 2 bits */
- item = &list[pos / 4];
- mask = mask << 2 * (pos % 4);
+ item = &list[pos / IFF_RECORDS_IN_BYTE];
+ mask = mask << IFF_RECORD_BITS * (pos % IFF_RECORDS_IN_BYTE);
*item = (*item) & ~mask;
- *item = (*item) | (op << 2 * (pos % 4));
+ *item = (*item) | (op << IFF_RECORD_BITS * (pos % IFF_RECORDS_IN_BYTE));
}
#define LYS_IFF_LP 0x04 /**< Additional, temporary, value of @ref ifftokens: ( */
@@ -283,7 +288,9 @@
continue;
}
- if (!strncmp(&c[i], "not", op_len = 3) || !strncmp(&c[i], "and", op_len = 3) || !strncmp(&c[i], "or", op_len = 2)) {
+ if (!strncmp(&c[i], "not", op_len = ly_strlen_const("not")) ||
+ !strncmp(&c[i], "and", op_len = ly_strlen_const("and")) ||
+ !strncmp(&c[i], "or", op_len = ly_strlen_const("or"))) {
uint64_t spaces;
for (spaces = 0; c[i + op_len + spaces] && isspace(c[i + op_len + spaces]); spaces++) {}
if (c[i + op_len + spaces] == '\0') {
@@ -354,7 +361,7 @@
/* allocate the memory */
LY_ARRAY_CREATE_RET(ctx, iff->features, f_size, LY_EMEM);
- iff->expr = calloc((j = (expr_size / 4) + ((expr_size % 4) ? 1 : 0)), sizeof *iff->expr);
+ iff->expr = calloc((j = (expr_size / IFF_RECORDS_IN_BYTE) + ((expr_size % IFF_RECORDS_IN_BYTE) ? 1 : 0)), sizeof *iff->expr);
stack.stack = malloc(expr_size * sizeof *stack.stack);
LY_CHECK_ERR_GOTO(!stack.stack || !iff->expr, LOGMEM(ctx); rc = LY_EMEM, error);
@@ -383,7 +390,7 @@
}
i++; /* go back by one step */
- if (!strncmp(&c[i], "not", 3) && isspace(c[i + 3])) {
+ if (!strncmp(&c[i], "not", ly_strlen_const("not")) && isspace(c[i + ly_strlen_const("not")])) {
if (stack.index && (stack.stack[stack.index - 1] == LYS_IFF_NOT)) {
/* double not */
iff_stack_pop(&stack);
@@ -392,7 +399,7 @@
* as in case of AND and OR */
iff_stack_push(&stack, LYS_IFF_NOT);
}
- } else if (!strncmp(&c[i], "and", 3) && isspace(c[i + 3])) {
+ } else if (!strncmp(&c[i], "and", ly_strlen_const("and")) && isspace(c[i + ly_strlen_const("and")])) {
/* as for OR - pop from the stack all operators with the same or higher
* priority and store them to the result, then push the AND to the stack */
while (stack.index && stack.stack[stack.index - 1] <= LYS_IFF_AND) {
diff --git a/src/set.c b/src/set.c
index 1eb229b..5ed43f4 100644
--- a/src/set.c
+++ b/src/set.c
@@ -141,10 +141,12 @@
}
if (set->size == set->count) {
- new = realloc(set->objs, (set->size + 8) * sizeof *(set->objs));
+#define SET_SIZE_STEP 8
+ new = realloc(set->objs, (set->size + SET_SIZE_STEP) * sizeof *(set->objs));
LY_CHECK_ERR_RET(!new, LOGMEM(NULL), LY_EMEM);
- set->size += 8;
+ set->size += SET_SIZE_STEP;
set->objs = new;
+#undef SET_SIZE_STEP
}
if (index_p) {
diff --git a/src/tree_data.c b/src/tree_data.c
index f8a9775..8ea215a 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -275,11 +275,14 @@
/* ignore trailing whitespaces */
for ( ; len > 0 && isspace(path[len - 1]); len--) {}
- if ((len >= 5) && !strncmp(&path[len - 4], ".xml", 4)) {
+ if ((len >= LY_XML_SUFFIX_LEN + 1) &&
+ !strncmp(&path[len - LY_XML_SUFFIX_LEN], LY_XML_SUFFIX, LY_XML_SUFFIX_LEN)) {
format = LYD_XML;
- } else if ((len >= 6) && !strncmp(&path[len - 5], ".json", 5)) {
+ } else if ((len >= LY_JSON_SUFFIX_LEN + 1) &&
+ !strncmp(&path[len - LY_JSON_SUFFIX_LEN], LY_JSON_SUFFIX, LY_JSON_SUFFIX_LEN)) {
format = LYD_JSON;
- } else if ((len >= 5) && !strncmp(&path[len - 4], ".lyb", 4)) {
+ } else if ((len >= LY_LYB_SUFFIX_LEN + 1) &&
+ !strncmp(&path[len - LY_LYB_SUFFIX_LEN], LY_LYB_SUFFIX, LY_LYB_SUFFIX_LEN)) {
format = LYD_LYB;
} /* else still unknown */
}
@@ -1342,7 +1345,7 @@
}
break;
}
- /* fallthrough */
+ /* fall through */
case LYS_CONTAINER:
case LYS_NOTIF:
case LYS_RPC:
@@ -3000,7 +3003,7 @@
char quot;
val = LYD_CANON_VALUE(node);
- len = 4 + strlen(val) + 2;
+ len = 4 + strlen(val) + 2; /* "[.='" + val + "']" */
LY_CHECK_RET(lyd_path_str_enlarge(buffer, buflen, *bufused + len, is_static));
quot = '\'';
diff --git a/src/tree_data_internal.h b/src/tree_data_internal.h
index bb8e27a..f4de881 100644
--- a/src/tree_data_internal.h
+++ b/src/tree_data_internal.h
@@ -26,6 +26,13 @@
struct ly_path_predicate;
struct lysc_module;
+#define LY_XML_SUFFIX ".xml"
+#define LY_XML_SUFFIX_LEN 4
+#define LY_JSON_SUFFIX ".json"
+#define LY_JSON_SUFFIX_LEN 5
+#define LY_LYB_SUFFIX ".lyb"
+#define LY_LYB_SUFFIX_LEN 4
+
/**
* @brief Internal data parser flags.
*/
diff --git a/src/tree_schema.c b/src/tree_schema.c
index 09bb2f7..38a09bd 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -285,7 +285,7 @@
LY_CHECK_ARG_RET(NULL, module, name, NULL);
if (!nodetype) {
- nodetype = 0xffff;
+ nodetype = LYS_NODETYPE_MASK;
}
while ((node = lys_getnext(node, parent, module->compiled, options))) {
@@ -381,7 +381,7 @@
(*set)->size = xp_set.used;
for (i = 0; i < xp_set.used; ++i) {
- if ((xp_set.val.scnodes[i].type == LYXP_NODE_ELEM) && (xp_set.val.scnodes[i].in_ctx == 1)) {
+ if ((xp_set.val.scnodes[i].type == LYXP_NODE_ELEM) && (xp_set.val.scnodes[i].in_ctx == LYXP_SET_SCNODE_ATOM_CTX)) {
ret = ly_set_add(*set, xp_set.val.scnodes[i].scnode, 1, NULL);
LY_CHECK_GOTO(ret, cleanup);
}
@@ -427,7 +427,7 @@
(*set)->size = xp_set.used;
for (i = 0; i < xp_set.used; ++i) {
- if ((xp_set.val.scnodes[i].type == LYXP_NODE_ELEM) && (xp_set.val.scnodes[i].in_ctx == 1)) {
+ if ((xp_set.val.scnodes[i].type == LYXP_NODE_ELEM) && (xp_set.val.scnodes[i].in_ctx == LYXP_SET_SCNODE_ATOM_CTX)) {
ret = ly_set_add(*set, xp_set.val.scnodes[i].scnode, 1, NULL);
LY_CHECK_GOTO(ret, cleanup);
}
@@ -1150,7 +1150,7 @@
}
if (rev) {
len = dot - ++rev;
- if (!mod->parsed->revs || (len != 10) || strncmp(mod->parsed->revs[0].date, rev, len)) {
+ if (!mod->parsed->revs || (len != LY_REV_SIZE - 1) || strncmp(mod->parsed->revs[0].date, rev, len)) {
LOGWRN(ctx, "File name \"%s\" does not match module revision \"%s\".", filename,
mod->parsed->revs ? mod->parsed->revs[0].date : "none");
}
@@ -1248,9 +1248,11 @@
/* ignore trailing whitespaces */
for ( ; len > 0 && isspace(path[len - 1]); len--) {}
- if ((len >= 5) && !strncmp(&path[len - 5], ".yang", 5)) {
+ if ((len >= LY_YANG_SUFFIX_LEN + 1) &&
+ !strncmp(&path[len - LY_YANG_SUFFIX_LEN], LY_YANG_SUFFIX, LY_YANG_SUFFIX_LEN)) {
format = LYS_IN_YANG;
- } else if ((len >= 6) && !strncmp(&path[len - 4], ".yin", 4)) {
+ } else if ((len >= LY_YIN_SUFFIX_LEN + 1) &&
+ !strncmp(&path[len - LY_YIN_SUFFIX_LEN], LY_YIN_SUFFIX, LY_YIN_SUFFIX_LEN)) {
format = LYS_IN_YIN;
} /* else still unknown */
}
@@ -1452,9 +1454,11 @@
/* get type according to filename suffix */
flen = strlen(file->d_name);
- if (!strcmp(&file->d_name[flen - 5], ".yang")) {
+ if ((flen >= LY_YANG_SUFFIX_LEN + 1) &&
+ !strcmp(&file->d_name[flen - LY_YANG_SUFFIX_LEN], LY_YANG_SUFFIX)) {
format_aux = LYS_IN_YANG;
- } else if (!strcmp(&file->d_name[flen - 4], ".yin")) {
+ } else if ((flen >= LY_YIN_SUFFIX_LEN + 1) &&
+ !strcmp(&file->d_name[flen - LY_YIN_SUFFIX_LEN], LY_YIN_SUFFIX)) {
format_aux = LYS_IN_YIN;
} else {
/* not supportde suffix/file format */
@@ -1490,7 +1494,8 @@
/* remember the revision and try to find the newest one */
if (match_name) {
if ((file->d_name[len] != '@') ||
- lysp_check_date(NULL, &file->d_name[len + 1], flen - ((format_aux == LYS_IN_YANG) ? 5 : 4) - len - 1, NULL)) {
+ lysp_check_date(NULL, &file->d_name[len + 1],
+ flen - ((format_aux == LYS_IN_YANG) ? LY_YANG_SUFFIX_LEN : LY_YIN_SUFFIX_LEN) - len - 1, NULL)) {
continue;
} else if ((match_name[match_len] == '@') &&
(strncmp(&match_name[match_len + 1], &file->d_name[len + 1], LY_REV_SIZE - 1) >= 0)) {
diff --git a/src/tree_schema.h b/src/tree_schema.h
index f7b854b..24bece7 100644
--- a/src/tree_schema.h
+++ b/src/tree_schema.h
@@ -260,6 +260,8 @@
#define LYS_GROUPING 0x4000
#define LYS_AUGMENT 0x8000
+#define LYS_NODETYPE_MASK 0xffff /**< Mask for nodetypes, the value is limited for 16 bits */
+
/**
* @brief List of YANG statements
*/
@@ -366,13 +368,15 @@
LYEXT_PAR_IDENT, /**< ::lysc_ident */
LYEXT_PAR_EXT, /**< ::lysc_ext */
LYEXT_PAR_IMPORT /**< ::lysp_import */
-// LYEXT_PAR_TPDF, /**< ::lysp_tpdf */
-// LYEXT_PAR_EXTINST, /**< ::lysp_ext_instance */
-// LYEXT_PAR_REFINE, /**< ::lysp_refine */
-// LYEXT_PAR_DEVIATION, /**< ::lysp_deviation */
-// LYEXT_PAR_DEVIATE, /**< ::lysp_deviate */
-// LYEXT_PAR_INCLUDE, /**< ::lysp_include */
-// LYEXT_PAR_REVISION, /**< ::lysp_revision */
+#if 0
+ LYEXT_PAR_TPDF, /**< ::lysp_tpdf */
+ LYEXT_PAR_EXTINST, /**< ::lysp_ext_instance */
+ LYEXT_PAR_REFINE, /**< ::lysp_refine */
+ LYEXT_PAR_DEVIATION, /**< ::lysp_deviation */
+ LYEXT_PAR_DEVIATE, /**< ::lysp_deviate */
+ LYEXT_PAR_INCLUDE, /**< ::lysp_include */
+ LYEXT_PAR_REVISION /**< ::lysp_revision */
+#endif
} LYEXT_PARENT;
/**
@@ -557,6 +561,8 @@
* @brief Covers restrictions: range, length, pattern, must
*/
struct lysp_restr {
+#define LYSP_RESTR_PATTERN_ACK 0x06
+#define LYSP_RESTR_PATTERN_NACK 0x15
struct lysp_qname arg; /**< The restriction expression/value (mandatory);
in case of pattern restriction, the first byte has a special meaning:
0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
diff --git a/src/tree_schema_helpers.c b/src/tree_schema_helpers.c
index b8fc9e9..7933d71 100644
--- a/src/tree_schema_helpers.c
+++ b/src/tree_schema_helpers.c
@@ -63,7 +63,7 @@
LY_CHECK_ARG_RET(ctx ? PARSER_CTX(ctx) : NULL, date, LY_EINVAL);
LY_CHECK_ERR_RET(date_len != LY_REV_SIZE - 1, LOGARG(ctx ? PARSER_CTX(ctx) : NULL, date_len), LY_EINVAL);
- /* check format */
+ /* check format: YYYY-MM-DD */
for (uint8_t i = 0; i < date_len; i++) {
if ((i == 4) || (i == 7)) {
if (date[i] != '-') {
@@ -497,8 +497,8 @@
LY_ERR ret = LY_SUCCESS;
/* check name collisions - typedefs and groupings */
- ids_global = lyht_new(8, sizeof(char *), lysp_id_cmp, NULL, 1);
- ids_scoped = lyht_new(8, sizeof(char *), lysp_id_cmp, NULL, 1);
+ ids_global = lyht_new(LYHT_MIN_SIZE, sizeof(char *), lysp_id_cmp, NULL, 1);
+ ids_scoped = lyht_new(LYHT_MIN_SIZE, sizeof(char *), lysp_id_cmp, NULL, 1);
LY_ARRAY_FOR(mod->typedefs, v) {
ret = lysp_check_dup_typedef(ctx, NULL, &mod->typedefs[v], ids_global, ids_scoped);
LY_CHECK_GOTO(ret, cleanup);
@@ -697,7 +697,7 @@
/* revision */
if (rev) {
len = dot - ++rev;
- if (!revs || (len != 10) || strncmp(revs[0].date, rev, len)) {
+ if (!revs || (len != LY_REV_SIZE - 1) || strncmp(revs[0].date, rev, len)) {
LOGWRN(ctx, "File name \"%s\" does not match module revision \"%s\".", filename,
revs ? revs[0].date : "none");
}
diff --git a/src/tree_schema_internal.h b/src/tree_schema_internal.h
index 4ee5aac..fd1a795 100644
--- a/src/tree_schema_internal.h
+++ b/src/tree_schema_internal.h
@@ -25,8 +25,15 @@
struct lysc_ctx;
struct lys_glob_unres;
+#define LY_YANG_SUFFIX ".yang"
+#define LY_YANG_SUFFIX_LEN 5
+#define LY_YIN_SUFFIX ".yin"
+#define LY_YIN_SUFFIX_LEN 4
+
#define YIN_NS_URI "urn:ietf:params:xml:ns:yang:yin:1"
+#define LY_PCRE2_MSG_LIMIT 256
+
/**
* @brief Check module version is at least 2 (YANG 1.1) because of the keyword presence.
* Logs error message and returns LY_EVALID in case of module in YANG version 1.0.
@@ -79,6 +86,12 @@
LOGWRN(PARSER_CTX(CTX), "Empty argument of %s statement does not make sense.", STMT); \
}
+/*
+ * Additional YANG constants
+ */
+#define Y_TAB_SPACES 8 /**< number of spaces instead of tab character */
+#define LY_TYPE_DEC64_FD_MAX 18 /**< Maximal value of decimal64's fraction-digits */
+
/**
* @brief List of YANG statement groups - the (sub)module's substatements
*/
diff --git a/src/validation.c b/src/validation.c
index f8bc3de..c59f012 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -855,7 +855,8 @@
path2 = lyd_path(second, LYD_PATH_LOG, NULL, 0);
/* use buffer to rebuild the unique string */
- uniq_str = malloc(1024);
+#define UNIQ_BUF_SIZE 1024
+ uniq_str = malloc(UNIQ_BUF_SIZE);
uniq_str[0] = '\0';
ptr = uniq_str;
LY_ARRAY_FOR(slist->uniques[u], v) {
@@ -864,7 +865,7 @@
++ptr;
}
ptr = lysc_path_until((struct lysc_node *)slist->uniques[u][v], (struct lysc_node *)slist, LYSC_PATH_LOG,
- ptr, 1024 - (ptr - uniq_str));
+ ptr, UNIQ_BUF_SIZE - (ptr - uniq_str));
if (!ptr) {
/* path will be incomplete, whatever */
break;
@@ -877,6 +878,8 @@
free(path1);
free(path2);
free(uniq_str);
+#undef UNIQ_BUF_SIZE
+
return 1;
}
@@ -931,8 +934,9 @@
}
} else if (set->count > 2) {
/* use hashes for comparison */
- /* first, allocate the table, the size depends on number of items in the set */
- for (i = 31; i > 0; i--) {
+ /* first, allocate the table, the size depends on number of items in the set,
+ * the following code detects number of upper zero bits in the items' counter value ... */
+ for (i = (sizeof set->count * CHAR_BIT) - 1; i > 0; i--) {
size = set->count << i;
size = size >> i;
if (size == set->count) {
@@ -940,7 +944,9 @@
}
}
LY_CHECK_ERR_GOTO(!i, LOGINT(ctx); ret = LY_EINT, cleanup);
- i = 32 - i;
+ /* ... and then we convert it to the position of the highest non-zero bit ... */
+ i = (sizeof set->count * CHAR_BIT) - i;
+ /* ... and by using it to shift 1 to the left we get the closest sufficient hash table size */
size = 1 << i;
uniqtables = malloc(LY_ARRAY_COUNT(uniques) * sizeof *uniqtables);
diff --git a/src/xml.c b/src/xml.c
index 516fe4b..8a1a7a2 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -255,14 +255,14 @@
move_input(xmlctx, 2);
sectname = "Comment";
endtag = "-->";
- endtag_len = 3;
- } else if (!strncmp(xmlctx->in->current, "[CDATA[", 7)) {
+ endtag_len = ly_strlen_const("-->");
+ } else if (!strncmp(xmlctx->in->current, "[CDATA[", ly_strlen_const("[CDATA["))) {
/* CDATA section */
- move_input(xmlctx, 7);
+ move_input(xmlctx, ly_strlen_const("[CDATA["));
sectname = "CData";
endtag = "]]>";
- endtag_len = 3;
- } else if (!strncmp(xmlctx->in->current, "DOCTYPE", 7)) {
+ endtag_len = ly_strlen_const("]]>");
+ } else if (!strncmp(xmlctx->in->current, "DOCTYPE", ly_strlen_const("DOCTYPE"))) {
/* Document type declaration - not supported */
LOGVAL(ctx, LY_VLOG_LINE, &xmlctx->line, LY_VCODE_NSUPP, "Document Type Declaration");
return LY_EVALID;
@@ -389,21 +389,21 @@
++offset;
if (in[offset] != '#') {
/* entity reference - only predefined references are supported */
- if (!strncmp(&in[offset], "lt;", 3)) {
+ if (!strncmp(&in[offset], "lt;", ly_strlen_const("lt;"))) {
buf[len++] = '<';
- in += 4; /* < */
- } else if (!strncmp(&in[offset], "gt;", 3)) {
+ in += ly_strlen_const("<");
+ } else if (!strncmp(&in[offset], "gt;", ly_strlen_const("gt;"))) {
buf[len++] = '>';
- in += 4; /* > */
- } else if (!strncmp(&in[offset], "amp;", 4)) {
+ in += ly_strlen_const(">");
+ } else if (!strncmp(&in[offset], "amp;", ly_strlen_const("amp;"))) {
buf[len++] = '&';
- in += 5; /* & */
- } else if (!strncmp(&in[offset], "apos;", 5)) {
+ in += ly_strlen_const("&");
+ } else if (!strncmp(&in[offset], "apos;", ly_strlen_const("apos;"))) {
buf[len++] = '\'';
- in += 6; /* ' */
- } else if (!strncmp(&in[offset], "quot;", 5)) {
+ in += ly_strlen_const("'");
+ } else if (!strncmp(&in[offset], "quot;", ly_strlen_const("quot;"))) {
buf[len++] = '\"';
- in += 6; /* " */
+ in += ly_strlen_const(""");
} else {
LOGVAL(ctx, LY_VLOG_LINE, &xmlctx->line, LYVE_SYNTAX,
"Entity reference \"%.*s\" not supported, only predefined references allowed.", 10, &in[offset - 1]);
@@ -416,18 +416,18 @@
++offset;
if (isdigit(in[offset])) {
for (n = 0; isdigit(in[offset]); offset++) {
- n = (10 * n) + (in[offset] - '0');
+ n = (LY_BASE_DEC * n) + (in[offset] - '0');
}
} else if ((in[offset] == 'x') && isxdigit(in[offset + 1])) {
for (n = 0, ++offset; isxdigit(in[offset]); offset++) {
if (isdigit(in[offset])) {
u = (in[offset] - '0');
} else if (in[offset] > 'F') {
- u = 10 + (in[offset] - 'a');
+ u = LY_BASE_DEC + (in[offset] - 'a');
} else {
- u = 10 + (in[offset] - 'A');
+ u = LY_BASE_DEC + (in[offset] - 'A');
}
- n = (16 * n) + u;
+ n = (LY_BASE_HEX * n) + u;
}
} else {
LOGVAL(ctx, LY_VLOG_LINE, &xmlctx->line, LYVE_SYNTAX, "Invalid character reference \"%.*s\".", 12, p);
@@ -847,8 +847,9 @@
}
switch (xmlctx->status) {
- /* content |</elem> */
case LYXML_ELEM_CONTENT:
+ /* content |</elem> */
+
/* handle special case when empty content for "<elem/>" was returned */
if (xmlctx->in->current[0] == '/') {
assert(xmlctx->elements.count);
@@ -862,10 +863,10 @@
xmlctx->status = LYXML_ELEM_CLOSE;
break;
}
- /* fallthrough */
-
- /* </elem>| <elem2>* */
+ /* fall through */
case LYXML_ELEM_CLOSE:
+ /* </elem>| <elem2>* */
+
/* parse next element, if any */
ret = lyxml_next_element(xmlctx, &xmlctx->prefix, &xmlctx->prefix_len, &xmlctx->name, &xmlctx->name_len, &closing);
LY_CHECK_GOTO(ret, cleanup);
@@ -890,11 +891,11 @@
}
break;
- /* <elem| attr='val'* > content */
case LYXML_ELEMENT:
-
- /* attr='val'| attr='val'* > content */
+ /* <elem| attr='val'* > content */
case LYXML_ATTR_CONTENT:
+ /* attr='val'| attr='val'* > content */
+
/* parse attribute name, if any */
ret = lyxml_next_attribute(xmlctx, &xmlctx->prefix, &xmlctx->prefix_len, &xmlctx->name, &xmlctx->name_len);
LY_CHECK_GOTO(ret, cleanup);
@@ -936,8 +937,9 @@
}
break;
- /* attr|='val' */
case LYXML_ATTRIBUTE:
+ /* attr|='val' */
+
/* skip formatting and parse value */
ret = lyxml_next_attr_content(xmlctx, &xmlctx->value, &xmlctx->value_len, &xmlctx->ws_only, &xmlctx->dynamic);
LY_CHECK_GOTO(ret, cleanup);
@@ -946,8 +948,8 @@
xmlctx->status = LYXML_ATTR_CONTENT;
break;
- /* </elem> |EOF */
case LYXML_END:
+ /* </elem> |EOF */
/* nothing to do */
break;
}
@@ -976,7 +978,7 @@
*next = LYXML_ELEM_CLOSE;
break;
}
- /* fallthrough */
+ /* fall through */
case LYXML_ELEM_CLOSE:
/* parse next element, if any */
ret = lyxml_next_element(xmlctx, &prefix, &prefix_len, &name, &name_len, &closing);
@@ -1064,7 +1066,7 @@
ret = ly_print_(out, """);
break;
}
- /* falls through */
+ /* fall through */
default:
ret = ly_write_(out, &text[u], 1);
break;
diff --git a/src/xpath.c b/src/xpath.c
index 811a8a0..7c3eb59 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -133,8 +133,9 @@
static void
print_expr_struct_debug(const struct lyxp_expr *exp)
{
+#define MSG_BUFFER_SIZE 128
+ char tmp[MSG_BUFFER_SIZE];
uint16_t i, j;
- char tmp[128];
if (!exp || (ly_ll < LY_LLDBG)) {
return;
@@ -153,6 +154,7 @@
}
LOGDBG(LY_LDGXPATH, tmp);
}
+#undef MSG_BUFFER_SIZE
}
#ifndef NDEBUG
@@ -781,7 +783,8 @@
ret->type = set->type;
for (i = 0; i < set->used; ++i) {
- if ((set->val.scnodes[i].in_ctx == 1) || (set->val.scnodes[i].in_ctx == -2)) {
+ if ((set->val.scnodes[i].in_ctx == LYXP_SET_SCNODE_ATOM_CTX) ||
+ (set->val.scnodes[i].in_ctx == LYXP_SET_SCNODE_START)) {
uint32_t idx;
LY_CHECK_ERR_RET(lyxp_set_scnode_insert_node(ret, set->val.scnodes[i].scnode, set->val.scnodes[i].type, &idx),
lyxp_set_free(ret), NULL);
@@ -935,10 +938,10 @@
uint32_t i;
for (i = 0; i < set->used; ++i) {
- if (set->val.scnodes[i].in_ctx == 1) {
- set->val.scnodes[i].in_ctx = 0;
- } else if (set->val.scnodes[i].in_ctx == -2) {
- set->val.scnodes[i].in_ctx = -1;
+ if (set->val.scnodes[i].in_ctx == LYXP_SET_SCNODE_ATOM_CTX) {
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_ATOM;
+ } else if (set->val.scnodes[i].in_ctx == LYXP_SET_SCNODE_START) {
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_START_USED;
}
}
}
@@ -1192,7 +1195,7 @@
assert(set->type == LYXP_SET_SCNODE_SET);
if (lyxp_set_scnode_contains(set, node, node_type, -1, &index)) {
- set->val.scnodes[index].in_ctx = 1;
+ set->val.scnodes[index].in_ctx = LYXP_SET_SCNODE_ATOM_CTX;
} else {
if (set->used == set->size) {
set->val.scnodes = ly_realloc(set->val.scnodes, (set->size + LYXP_SET_SIZE_STEP) * sizeof *set->val.scnodes);
@@ -1203,7 +1206,7 @@
index = set->used;
set->val.scnodes[index].scnode = (struct lysc_node *)node;
set->val.scnodes[index].type = node_type;
- set->val.scnodes[index].in_ctx = 1;
+ set->val.scnodes[index].in_ctx = LYXP_SET_SCNODE_ATOM_CTX;
++set->used;
}
@@ -1253,7 +1256,7 @@
assert(set->type == LYXP_SET_SCNODE_SET);
- ret_ctx = 3;
+ ret_ctx = LYXP_SET_SCNODE_ATOM_PRED_CTX;
retry:
for (i = 0; i < set->used; ++i) {
if (set->val.scnodes[i].in_ctx >= ret_ctx) {
@@ -1262,7 +1265,7 @@
}
}
for (i = 0; i < set->used; ++i) {
- if (set->val.scnodes[i].in_ctx == 1) {
+ if (set->val.scnodes[i].in_ctx == LYXP_SET_SCNODE_ATOM_CTX) {
set->val.scnodes[i].in_ctx = ret_ctx;
}
}
@@ -1377,7 +1380,7 @@
if (!tmp_node) {
LOGINT_RET(root->schema->module->ctx);
}
- /* fallthrough */
+ /* fall through */
case LYXP_NODE_ELEM:
case LYXP_NODE_TEXT:
if (!tmp_node) {
@@ -3028,7 +3031,7 @@
i = set->used;
do {
--i;
- if (set->val.scnodes[i].in_ctx == 1) {
+ if (set->val.scnodes[i].in_ctx == LYXP_SET_SCNODE_ATOM_CTX) {
/* if there are more, simply return the first found (last added) */
return set->val.scnodes[i].scnode;
}
@@ -5021,7 +5024,7 @@
if (options & LYXP_SCNODE_ALL) {
if (args[0]->type == LYXP_SET_SCNODE_SET) {
for (i = 0; i < args[0]->used; ++i) {
- if (args[0]->val.scnodes[i].in_ctx == 1) {
+ if (args[0]->val.scnodes[i].in_ctx == LYXP_SET_SCNODE_ATOM_CTX) {
sleaf = (struct lysc_node_leaf *)args[0]->val.scnodes[i].scnode;
if (!(sleaf->nodetype & (LYS_LEAF | LYS_LEAFLIST))) {
LOGWRN(set->ctx, "Argument #1 of %s is a %s node \"%s\".", __func__,
@@ -5648,15 +5651,15 @@
for (i = 0; i < orig_used; ++i) {
uint32_t idx;
- if (set->val.scnodes[i].in_ctx != 1) {
- if (set->val.scnodes[i].in_ctx != -2) {
+ if (set->val.scnodes[i].in_ctx != LYXP_SET_SCNODE_ATOM_CTX) {
+ if (set->val.scnodes[i].in_ctx != LYXP_SET_SCNODE_START) {
continue;
}
/* remember context node */
- set->val.scnodes[i].in_ctx = -1;
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_START_USED;
} else {
- set->val.scnodes[i].in_ctx = 0;
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_ATOM;
}
start_parent = set->val.scnodes[i].scnode;
@@ -5674,7 +5677,7 @@
/* we need to prevent these nodes from being considered in this moveto */
if ((idx < orig_used) && (idx > i)) {
- set->val.scnodes[idx].in_ctx = 2;
+ set->val.scnodes[idx].in_ctx = LYXP_SET_SCNODE_ATOM_NEW_CTX;
temp_ctx = 1;
}
}
@@ -5688,7 +5691,7 @@
LY_CHECK_RET(lyxp_set_scnode_insert_node(set, iter, LYXP_NODE_ELEM, &idx));
if ((idx < orig_used) && (idx > i)) {
- set->val.scnodes[idx].in_ctx = 2;
+ set->val.scnodes[idx].in_ctx = LYXP_SET_SCNODE_ATOM_NEW_CTX;
temp_ctx = 1;
}
}
@@ -5699,8 +5702,8 @@
/* correct temporary in_ctx values */
if (temp_ctx) {
for (i = 0; i < orig_used; ++i) {
- if (set->val.scnodes[i].in_ctx == 2) {
- set->val.scnodes[i].in_ctx = 1;
+ if (set->val.scnodes[i].in_ctx == LYXP_SET_SCNODE_ATOM_NEW_CTX) {
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_ATOM_CTX;
}
}
}
@@ -5822,15 +5825,15 @@
orig_used = set->used;
for (i = 0; i < orig_used; ++i) {
- if (set->val.scnodes[i].in_ctx != 1) {
- if (set->val.scnodes[i].in_ctx != -2) {
+ if (set->val.scnodes[i].in_ctx != LYXP_SET_SCNODE_ATOM_CTX) {
+ if (set->val.scnodes[i].in_ctx != LYXP_SET_SCNODE_START) {
continue;
}
/* remember context node */
- set->val.scnodes[i].in_ctx = -1;
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_START_USED;
} else {
- set->val.scnodes[i].in_ctx = 0;
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_ATOM;
}
/* TREE DFS */
@@ -5846,7 +5849,7 @@
uint32_t idx;
if (lyxp_set_scnode_contains(set, elem, LYXP_NODE_ELEM, i, &idx)) {
- set->val.scnodes[idx].in_ctx = 1;
+ set->val.scnodes[idx].in_ctx = LYXP_SET_SCNODE_ATOM_CTX;
if ((uint32_t)idx > i) {
/* we will process it later in the set */
goto skip_children;
@@ -6235,15 +6238,15 @@
/* add all the children, recursively as they are being added into the same set */
for (uint32_t i = 0; i < set->used; ++i) {
- if (set->val.scnodes[i].in_ctx != 1) {
- if (set->val.scnodes[i].in_ctx != -2) {
+ if (set->val.scnodes[i].in_ctx != LYXP_SET_SCNODE_ATOM_CTX) {
+ if (set->val.scnodes[i].in_ctx != LYXP_SET_SCNODE_START) {
continue;
}
/* remember context node */
- set->val.scnodes[i].in_ctx = -1;
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_START_USED;
} else {
- set->val.scnodes[i].in_ctx = 0;
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_ATOM;
}
start_parent = set->val.scnodes[i].scnode;
@@ -6390,15 +6393,15 @@
orig_used = set->used;
for (i = 0; i < orig_used; ++i) {
- if (set->val.scnodes[i].in_ctx != 1) {
- if (set->val.scnodes[i].in_ctx != -2) {
+ if (set->val.scnodes[i].in_ctx != LYXP_SET_SCNODE_ATOM_CTX) {
+ if (set->val.scnodes[i].in_ctx != LYXP_SET_SCNODE_START) {
continue;
}
/* remember context node */
- set->val.scnodes[i].in_ctx = -1;
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_START_USED;
} else {
- set->val.scnodes[i].in_ctx = 0;
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_ATOM;
}
node = set->val.scnodes[i].scnode;
@@ -6421,15 +6424,15 @@
LY_CHECK_RET(lyxp_set_scnode_insert_node(set, new_node, new_type, &idx));
if ((idx < orig_used) && (idx > i)) {
- set->val.scnodes[idx].in_ctx = 2;
+ set->val.scnodes[idx].in_ctx = LYXP_SET_SCNODE_ATOM_NEW_CTX;
temp_ctx = 1;
}
}
if (temp_ctx) {
for (i = 0; i < orig_used; ++i) {
- if (set->val.scnodes[i].in_ctx == 2) {
- set->val.scnodes[i].in_ctx = 1;
+ if (set->val.scnodes[i].in_ctx == LYXP_SET_SCNODE_ATOM_NEW_CTX) {
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_ATOM_CTX;
}
}
}
@@ -6779,7 +6782,7 @@
} else if (set->type == LYXP_SET_SCNODE_SET) {
for (i = 0; i < set->used; ++i) {
- if (set->val.scnodes[i].in_ctx == 1) {
+ if (set->val.scnodes[i].in_ctx == LYXP_SET_SCNODE_ATOM_CTX) {
/* there is a currently-valid node */
break;
}
@@ -6799,7 +6802,7 @@
if (set->val.scnodes[i].in_ctx != pred_in_ctx) {
continue;
}
- set->val.scnodes[i].in_ctx = 1;
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_ATOM_CTX;
*tok_idx = orig_exp;
@@ -6811,10 +6814,10 @@
/* restore the state as it was before the predicate */
for (i = 0; i < set->used; ++i) {
- if (set->val.scnodes[i].in_ctx == 1) {
- set->val.scnodes[i].in_ctx = 0;
+ if (set->val.scnodes[i].in_ctx == LYXP_SET_SCNODE_ATOM_CTX) {
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_ATOM;
} else if (set->val.scnodes[i].in_ctx == pred_in_ctx) {
- set->val.scnodes[i].in_ctx = 1;
+ set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_ATOM_CTX;
}
}
@@ -7162,7 +7165,7 @@
LY_CHECK_GOTO(rc, cleanup);
for (i = set->used - 1; i > -1; --i) {
- if (set->val.scnodes[i].in_ctx > 0) {
+ if (set->val.scnodes[i].in_ctx > LYXP_SET_SCNODE_ATOM) {
break;
}
}
@@ -8737,7 +8740,7 @@
set->type = LYXP_SET_SCNODE_SET;
set->root_type = lyxp_get_root_type(NULL, ctx_scnode, options);
LY_CHECK_RET(lyxp_set_scnode_insert_node(set, ctx_scnode, ctx_scnode ? LYXP_NODE_ELEM : set->root_type, NULL));
- set->val.scnodes[0].in_ctx = -2;
+ set->val.scnodes[0].in_ctx = LYXP_SET_SCNODE_START;
set->ctx = cur_mod ? cur_mod->ctx : (ctx_scnode ? ctx_scnode->module->ctx : NULL);
set->cur_scnode = ctx_scnode;
diff --git a/src/xpath.h b/src/xpath.h
index 5b04457..d53bceb 100644
--- a/src/xpath.h
+++ b/src/xpath.h
@@ -223,13 +223,15 @@
struct lyxp_set_scnode {
struct lysc_node *scnode;
enum lyxp_node_type type;
- /* -2 - scnode not traversed, currently (the only node) in context;
- * -1 - scnode not traversed except for the eval start, not currently in the context;
- * 0 - scnode was traversed, but not currently in the context;
- * 1 - scnode currently in context;
- * 2 - scnode in context and just added, so skip it for the current operation;
- * >=3 - scnode is not in context because we are in a predicate and this scnode was used/will be used later */
- int32_t in_ctx;
+
+#define LYXP_SET_SCNODE_START -2 /**< scnode not traversed, currently (the only node) in context */
+#define LYXP_SET_SCNODE_START_USED -1 /**< scnode not traversed except for the eval start, not currently in the context */
+#define LYXP_SET_SCNODE_ATOM 0 /**< scnode was traversed, but not currently in the context */
+#define LYXP_SET_SCNODE_ATOM_CTX 1 /**< scnode currently in context */
+#define LYXP_SET_SCNODE_ATOM_NEW_CTX 2 /**< scnode in context and just added, so skip it for the current operation */
+#define LYXP_SET_SCNODE_ATOM_PRED_CTX 3 /**< includes any higher value - scnode is not in context because we are in
+ a predicate and this scnode was used/will be used later */
+ int32_t in_ctx; /**< values defined as LYXP_SET_SCNODE_* */
} *scnodes;
struct lyxp_set_meta {
struct lyd_meta *meta;
diff --git a/tools/lint/main_ni.c b/tools/lint/main_ni.c
index 8886dfb..3559f73 100644
--- a/tools/lint/main_ni.c
+++ b/tools/lint/main_ni.c
@@ -638,12 +638,12 @@
const char *ptr = optarg;
while (ptr[0]) {
- if (!strncasecmp(ptr, "dict", 4)) {
+ if (!strncasecmp(ptr, "dict", sizeof "dict" - 1)) {
dbg_groups |= LY_LDGDICT;
- ptr += 4;
- } else if (!strncasecmp(ptr, "xpath", 5)) {
+ ptr += sizeof "dict" - 1;
+ } else if (!strncasecmp(ptr, "xpath", sizeof "xpath" - 1)) {
dbg_groups |= LY_LDGXPATH;
- ptr += 5;
+ ptr += sizeof "xpath" - 1;
}
if (ptr[0]) {