mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 06:39:17 +02:00
checking for OOM in sexp_read_symbol
This commit is contained in:
parent
54f913fa2a
commit
c9f279ea28
1 changed files with 6 additions and 3 deletions
9
sexp.c
9
sexp.c
|
@ -1578,7 +1578,7 @@ sexp sexp_read_symbol (sexp ctx, sexp in, int init, int internp) {
|
||||||
int c, i=0, size=INIT_STRING_BUFFER_SIZE;
|
int c, i=0, size=INIT_STRING_BUFFER_SIZE;
|
||||||
char initbuf[INIT_STRING_BUFFER_SIZE];
|
char initbuf[INIT_STRING_BUFFER_SIZE];
|
||||||
char *buf=initbuf, *tmp;
|
char *buf=initbuf, *tmp;
|
||||||
sexp res;
|
sexp res=SEXP_VOID;
|
||||||
#if SEXP_USE_FOLD_CASE_SYMS
|
#if SEXP_USE_FOLD_CASE_SYMS
|
||||||
int foldp = sexp_port_fold_casep(in);
|
int foldp = sexp_port_fold_casep(in);
|
||||||
init = (foldp ? tolower(init) : init);
|
init = (foldp ? tolower(init) : init);
|
||||||
|
@ -1599,6 +1599,7 @@ sexp sexp_read_symbol (sexp ctx, sexp in, int init, int internp) {
|
||||||
buf[i++] = c;
|
buf[i++] = c;
|
||||||
if (i >= size) { /* expand buffer w/ malloc(), later free() it */
|
if (i >= size) { /* expand buffer w/ malloc(), later free() it */
|
||||||
tmp = (char*) sexp_malloc(size*2);
|
tmp = (char*) sexp_malloc(size*2);
|
||||||
|
if (!tmp) {res = sexp_global(ctx, SEXP_G_OOM_ERROR); break;}
|
||||||
memcpy(tmp, buf, i);
|
memcpy(tmp, buf, i);
|
||||||
if (size != INIT_STRING_BUFFER_SIZE) free(buf);
|
if (size != INIT_STRING_BUFFER_SIZE) free(buf);
|
||||||
buf = tmp;
|
buf = tmp;
|
||||||
|
@ -1606,8 +1607,10 @@ sexp sexp_read_symbol (sexp ctx, sexp in, int init, int internp) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[i] = '\0';
|
if (!sexp_exceptionp(res)) {
|
||||||
res = (internp ? sexp_intern(ctx, buf, i) : sexp_c_string(ctx, buf, i));
|
buf[i] = '\0';
|
||||||
|
res = (internp ? sexp_intern(ctx, buf, i) : sexp_c_string(ctx, buf, i));
|
||||||
|
}
|
||||||
if (size != INIT_STRING_BUFFER_SIZE) free(buf);
|
if (size != INIT_STRING_BUFFER_SIZE) free(buf);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue