allocate space

This commit is contained in:
Vitor Santos Costa 2016-09-30 17:10:01 -05:00
parent ef38613229
commit 41ccbf7367
3 changed files with 9 additions and 5 deletions

View File

@ -370,7 +370,6 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
s = (char *)s0;
else
s = Malloc(0);
AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), s, char);
if (snprintf(s, MaxTmp(PASS_REGS1) - 1, Int_FORMAT,
IntegerOfTerm(inp->val.t)) < 0) {
AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char);

View File

@ -1275,7 +1275,8 @@ char *Yap_TermToString(Term t, size_t *lengthp, encoding_t enc, int flags) {
CACHE_REGS
int sno = Yap_open_buf_write_stream(enc, flags);
const char *sf;
DBTerm *e = LOCAL_BallTerm;
if (sno < 0)
return NULL;
LOCAL_c_output_stream = sno;
@ -1286,8 +1287,11 @@ char *Yap_TermToString(Term t, size_t *lengthp, encoding_t enc, int flags) {
Yap_plwrite(t, GLOBAL_Stream + sno, 0, flags, GLOBAL_MaxPriority);
sf = Yap_MemExportStreamPtr(sno);
size_t len = strlen(sf);
char *new = malloc( len + 1 );
strcpy( new, sf );
Yap_CloseStream(sno);
if (Yap_HasException())
return NULL;
return (char *)sf;
if (e)
LOCAL_BallTerm = e;
return new;
}

View File

@ -806,6 +806,7 @@ static inline char *Yap_AtomToUTF8Text(Atom at, const char *s USES_REGS) {
out.val.c0 = s;
out.type |= YAP_STRING_WITH_BUFFER;
} else {
out.type |= YAP_STRING_MALLOC;
out.val.c = NULL;
}
if (!Yap_CVT_Text(&inp, &out PASS_REGS))