schema compile BUGFIX invalid memory access
Fixes #1641
diff --git a/src/schema_compile_amend.c b/src/schema_compile_amend.c
index c44ed6e..9353be6 100644
--- a/src/schema_compile_amend.c
+++ b/src/schema_compile_amend.c
@@ -2330,7 +2330,7 @@
if (m->augmented_by[u] == mod) {
/* keep the order */
if (u < count - 1) {
- memmove(m->augmented_by + u, m->augmented_by + u + 1, (count - u) * sizeof *m->augmented_by);
+ memmove(m->augmented_by + u, m->augmented_by + u + 1, (count - u - 1) * sizeof *m->augmented_by);
}
LY_ARRAY_DECREMENT(m->augmented_by);
break;
@@ -2348,7 +2348,7 @@
if (m->deviated_by[u] == mod) {
/* keep the order */
if (u < count - 1) {
- memmove(m->deviated_by + u, m->deviated_by + u + 1, (count - u) * sizeof *m->deviated_by);
+ memmove(m->deviated_by + u, m->deviated_by + u + 1, (count - u - 1) * sizeof *m->deviated_by);
}
LY_ARRAY_DECREMENT(m->deviated_by);
break;