diff --git a/src/lib/internal.h b/src/lib/internal.h index 5addbac11..e958f8aa8 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -385,9 +385,9 @@ static inline char* pool_egc_copy(const egcpool* e, const cell* c){ char* ret; if(cell_simple_p(c)){ - if( (ret = (char*)malloc(2)) ){ - ret[0] = c->gcluster; - ret[1] = '\0'; + if( (ret = (char*)malloc(sizeof(c->gcluster) + 1)) ){ + memset(ret, 0, sizeof(c->gcluster) + 1); + memcpy(ret, &c->gcluster, sizeof(c->gcluster)); } }else{ ret = strdup(egcpool_extended_gcluster(e, c)); @@ -599,7 +599,7 @@ cell_duplicate_far(egcpool* tpool, cell* targ, const ncplane* splane, const cell targ->channels = c->channels; if(cell_simple_p(c)){ targ->gcluster = c->gcluster; - return !!c->gcluster; + return strnlen((char*)&c->gcluster, sizeof(c->gcluster)); } assert(splane); const char* egc = extended_gcluster(splane, c); diff --git a/tests/wide.cpp b/tests/wide.cpp index 0ba658c22..a8b4ed366 100644 --- a/tests/wide.cpp +++ b/tests/wide.cpp @@ -418,8 +418,10 @@ TEST_CASE("Wide") { free(egc); cell cl = CELL_TRIVIAL_INITIALIZER, cr = CELL_TRIVIAL_INITIALIZER; CHECK(3 == ncplane_at_yx_cell(n_, 1, 1, &cl)); - REQUIRE(cell_extended_gcluster(n_, &cl)); - CHECK(0 == strcmp("六", extended_gcluster(n_, &cl))); + egc = cell_strdup(n_, &cl); + REQUIRE(nullptr != egc); + CHECK(0 == strcmp("六", egc)); + free(egc); CHECK(0 == ncplane_at_yx_cell(n_, 1, 2, &cr)); REQUIRE(cell_simple_p(&cr)); CHECK(0 == cr.gcluster);