Skip to content

Commit 454b1c8

Browse files
committed
schema mount BUGFIX aligned printed ext instance
1 parent 86defdc commit 454b1c8

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/plugins_exts/schema_mount.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ struct sprinter_tree_priv {
7979
lyplg_ext_compile_log(cctx, ext, LY_LLERR, LY_EINT, "Internal error (%s:%d).", __FILE__, __LINE__); \
8080
return LY_EINT
8181

82+
#define CTXP_MEM_SIZE(SIZE) ((SIZE) + ((~(SIZE) + 1) & (8 - 1)))
83+
8284
/**
8385
* @brief Check if given mount point is unique among its siblings
8486
*
@@ -1508,20 +1510,20 @@ schema_mount_compiled_size(const struct lysc_ext_instance *ext, struct ly_ht *ad
15081510
return 0;
15091511
}
15101512

1511-
size += sizeof *sm_data;
1513+
size += CTXP_MEM_SIZE(sizeof *sm_data);
15121514

15131515
/* ht addr check, make sure the shared context is stored only once */
15141516
hash = lyht_hash((const char *)&sm_data->shared, sizeof sm_data->shared);
15151517
if (lyht_insert(addr_ht, &sm_data->shared, hash, NULL) == LY_EEXIST) {
15161518
return size;
15171519
}
15181520

1519-
size += sizeof *sm_data->shared;
1520-
size += sm_data->shared->schema_count * sizeof *sm_data->shared->schemas;
1521+
size += CTXP_MEM_SIZE(sizeof *sm_data->shared);
1522+
size += CTXP_MEM_SIZE(sm_data->shared->schema_count * sizeof *sm_data->shared->schemas);
15211523
for (i = 0; i < sm_data->shared->schema_count; ++i) {
1522-
size += ly_ctx_compiled_size(sm_data->shared->schemas[i].ctx);
1523-
size += strlen(sm_data->shared->schemas[i].mount_point) + 1;
1524-
size += strlen(sm_data->shared->schemas[i].content_id) + 1;
1524+
size += CTXP_MEM_SIZE(ly_ctx_compiled_size(sm_data->shared->schemas[i].ctx));
1525+
size += CTXP_MEM_SIZE(strlen(sm_data->shared->schemas[i].mount_point) + 1);
1526+
size += CTXP_MEM_SIZE(strlen(sm_data->shared->schemas[i].content_id) + 1);
15251527
}
15261528

15271529
/* inlined contexts cannot be reused and will not be printed */
@@ -1541,7 +1543,7 @@ schema_mount_compiled_print(const struct lysc_ext_instance *orig_ext, struct lys
15411543

15421544
/* sm_data */
15431545
ext->compiled = sm_data = *mem;
1544-
*mem = (char *)*mem + sizeof *sm_data;
1546+
*mem = (char *)*mem + CTXP_MEM_SIZE(sizeof *sm_data);
15451547

15461548
pthread_mutexattr_init(&attr);
15471549
pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
@@ -1557,15 +1559,15 @@ schema_mount_compiled_print(const struct lysc_ext_instance *orig_ext, struct lys
15571559

15581560
/* sm_data->shared */
15591561
sm_data->shared = *mem;
1560-
*mem = (char *)*mem + sizeof *sm_data->shared;
1562+
*mem = (char *)*mem + CTXP_MEM_SIZE(sizeof *sm_data->shared);
15611563

15621564
sm_data->shared->schema_count = orig_sm_data->shared->schema_count;
15631565
sm_data->shared->ref_count = orig_sm_data->shared->ref_count;
15641566

15651567
/* sm_data->shared->schemas */
15661568
if (orig_sm_data->shared->schemas) {
15671569
sm_data->shared->schemas = *mem;
1568-
*mem = (char *)*mem + sm_data->shared->schema_count * sizeof *sm_data->shared->schemas;
1570+
*mem = (char *)*mem + CTXP_MEM_SIZE(sm_data->shared->schema_count * sizeof *sm_data->shared->schemas);
15691571

15701572
for (i = 0; i < sm_data->shared->schema_count; ++i) {
15711573
/* ctx */
@@ -1578,12 +1580,12 @@ schema_mount_compiled_print(const struct lysc_ext_instance *orig_ext, struct lys
15781580
/* mount_point */
15791581
strcpy(*mem, orig_sm_data->shared->schemas[i].mount_point);
15801582
sm_data->shared->schemas[i].mount_point = *mem;
1581-
*mem = (char *)*mem + strlen(sm_data->shared->schemas[i].mount_point) + 1;
1583+
*mem = (char *)*mem + CTXP_MEM_SIZE(strlen(sm_data->shared->schemas[i].mount_point) + 1);
15821584

15831585
/* content_id */
15841586
strcpy(*mem, orig_sm_data->shared->schemas[i].content_id);
15851587
sm_data->shared->schemas[i].content_id = *mem;
1586-
*mem = (char *)*mem + strlen(sm_data->shared->schemas[i].content_id) + 1;
1588+
*mem = (char *)*mem + CTXP_MEM_SIZE(strlen(sm_data->shared->schemas[i].content_id) + 1);
15871589
}
15881590
}
15891591

0 commit comments

Comments
 (0)