Skip to content

Commit

Permalink
Stack allocate the OutBuffer and HdrGenState objects.
Browse files Browse the repository at this point in the history
Copy the string from the OutBuffer into a heap allocated string so it is valid.
  • Loading branch information
jmaschme committed May 15, 2012
1 parent ae47ac0 commit 167d69a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/traits.c
Expand Up @@ -229,10 +229,12 @@ Expression *TraitsExp::semantic(Scope *sc)
{
goto Lfalse;
}
OutBuffer *outBuffer = new OutBuffer();
HdrGenState *hgs = new HdrGenState();
s->toCBuffer(outBuffer, hgs);
return (new StringExp(loc, (char*)outBuffer->data))->semantic(sc);
OutBuffer outBuffer;
HdrGenState hgs;
s->toCBuffer(&outBuffer, &hgs);
char* code = (char*)malloc(outBuffer.size);
strcpy(code, (char*)outBuffer.data);
return (new StringExp(loc, code))->semantic(sc);
}

#endif
Expand Down

0 comments on commit 167d69a

Please sign in to comment.