Skip to content

Commit

Permalink
fix Issue 15369 - id.d(369): Error: Outside Unicode code space
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Nov 22, 2015
1 parent 913ffbe commit f13d425
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/backend/dt.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,25 @@ dt_t ** dtnbytes(dt_t **pdtend,unsigned size,const char *ptr)
* Construct a DTabytes record, and return it.
*/

dt_t **dtabytes(dt_t **pdtend, unsigned offset, unsigned size, const char *ptr, unsigned nbytes)
dt_t **dtabytes(dt_t **pdtend, unsigned offset, unsigned size, const char *ptr, unsigned nzeros)
{
return dtabytes(pdtend, TYnptr, offset, size, ptr, nbytes);
return dtabytes(pdtend, TYnptr, offset, size, ptr, nzeros);
}

dt_t **dtabytes(dt_t **pdtend,tym_t ty, unsigned offset, unsigned size, const char *ptr, unsigned nbytes)
dt_t **dtabytes(dt_t **pdtend, tym_t ty, unsigned offset, unsigned size, const char *ptr, unsigned nzeros)
{ dt_t *dt;

while (*pdtend)
pdtend = &((*pdtend)->DTnext);

dt = dt_calloc(DT_abytes);
dt->DTnbytes = size + nbytes;
dt->DTpbytes = (char *) MEM_PH_MALLOC(size + nbytes);
dt->DTnbytes = size + nzeros;
dt->DTpbytes = (char *) MEM_PH_MALLOC(size + nzeros);
dt->Dty = ty;
dt->DTabytes = offset;
memcpy(dt->DTpbytes,ptr,size);
if (size)
memset(dt->DTpbytes + size, 0, nbytes);
if (nzeros)
memset(dt->DTpbytes + size, 0, nzeros);

*pdtend = dt;
pdtend = &dt->DTnext;
Expand Down
3 changes: 3 additions & 0 deletions src/todt.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ dt_t **Expression_toDt(Expression *e, dt_t **pdt)
{
case Tarray:
pdt = dtsize_t(pdt, n);
pdt = dtabytes(pdt, 0, n * e->sz, p, (unsigned)e->sz);
break;

case Tpointer:
pdt = dtabytes(pdt, 0, n * e->sz, p, (unsigned)e->sz);
break;
Expand Down
24 changes: 24 additions & 0 deletions test/runnable/xtest46.d
Original file line number Diff line number Diff line change
Expand Up @@ -7713,6 +7713,29 @@ struct S15366
}
}

/***************************************************/
// 15369

struct MsgTable15369
{
const(char)[] ident;
const(char)* name;
};

MsgTable15369[] msgTable15369 =
[
{ "empty", "" },
];

void test15369()
{
auto id = msgTable15369[0].ident;
auto p = msgTable15369[0].name;

// a string literal "" should be zero-terminated
assert(*p == '\0');
}

/***************************************************/

int main()
Expand Down Expand Up @@ -8027,6 +8050,7 @@ int main()
test13985();
test14211();
test15141();
test15369();

printf("Success\n");
return 0;
Expand Down

0 comments on commit f13d425

Please sign in to comment.