Skip to content

Commit c61241d

Browse files
committed
to_string of cons bug (crash) fixed
1 parent 65fae37 commit c61241d

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

arc.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,41 +1824,40 @@ A symbol can be coerced to a string.
18241824

18251825
/* end builtin */
18261826

1827-
std::string to_string(const atom &a, int write) {
1827+
std::string to_string(atom a, int write) {
18281828
std::string s;
18291829
switch (a.type) {
18301830
case T_NIL:
18311831
s = "nil";
18321832
break;
18331833
case T_CONS: {
1834-
atom a2 = a;
1835-
if (listp(a2) && len(a2) == 2) {
1836-
if (is(car(a2), sym_quote)) {
1837-
s = "'" + to_string(car(cdr(a2)), write);
1834+
if (listp(a) && len(a) == 2) {
1835+
if (is(car(a), sym_quote)) {
1836+
s = "'" + to_string(car(cdr(a)), write);
18381837
break;
18391838
}
1840-
else if (is(car(a2), sym_quasiquote)) {
1841-
s = "`" + to_string(car(cdr(a2)), write);
1839+
else if (is(car(a), sym_quasiquote)) {
1840+
s = "`" + to_string(car(cdr(a)), write);
18421841
break;
18431842
}
1844-
else if (is(car(a2), sym_unquote)) {
1845-
s = "," + to_string(car(cdr(a2)), write);
1843+
else if (is(car(a), sym_unquote)) {
1844+
s = "," + to_string(car(cdr(a)), write);
18461845
break;
18471846
}
1848-
else if (is(car(a2), sym_unquote_splicing)) {
1849-
s = ",@" + to_string(car(cdr(a2)), write);
1847+
else if (is(car(a), sym_unquote_splicing)) {
1848+
s = ",@" + to_string(car(cdr(a)), write);
18501849
break;
18511850
}
18521851
}
1853-
s = "(" + to_string(car(a2), write);
1854-
a2 = cdr(a2);
1855-
while (!no(a2)) {
1852+
s = "(" + to_string(car(a), write);
1853+
a = cdr(a);
1854+
while (!no(a)) {
18561855
if (a.type == T_CONS) {
1857-
s += " " + to_string(car(a2), write);
1858-
a2 = cdr(a2);
1856+
s += " " + to_string(car(a), write);
1857+
a = cdr(a);
18591858
}
18601859
else {
1861-
s += " . " + to_string(a2, write);
1860+
s += " . " + to_string(a, write);
18621861
break;
18631862
}
18641863
}

arc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#endif
3535

3636
namespace arc {
37-
constexpr auto VERSION = "0.27";
37+
constexpr auto VERSION = "0.28";
3838

3939
enum type {
4040
T_NIL,
@@ -100,7 +100,7 @@ namespace arc {
100100
char *slurp(const char *path);
101101
error eval_expr(atom expr, std::shared_ptr<struct env> env, atom *result);
102102
error macex(atom expr, atom *result);
103-
std::string to_string(const atom &a, int write);
103+
std::string to_string(atom a, int write);
104104
error macex_eval(atom expr, atom *result);
105105
error arc_load_file(const char *path);
106106
void arc_init();

0 commit comments

Comments
 (0)