cell_duplicate_far() fix length issue

pull/893/head
nick black 4 years ago committed by Nick Black
parent 7ac3f68f4e
commit 2656cad07a

@ -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);

@ -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);

Loading…
Cancel
Save