diff --git a/src/libnix/expr.cc b/src/libnix/expr.cc index cead80342..9bbe80ab4 100644 --- a/src/libnix/expr.cc +++ b/src/libnix/expr.cc @@ -6,13 +6,21 @@ string printTerm(ATerm t) { char * s = ATwriteToString(t); + if (!s) throw Error("cannot print term"); return s; } Error badTerm(const format & f, ATerm t) { - return Error(format("%1%, in `%2%'") % f.str() % printTerm(t)); + char * s = ATwriteToString(t); + if (!s) throw Error("cannot print term"); + if (strlen(s) > 1000) { + int len; + s = ATwriteToSharedString(t, &len); + if (!s) throw Error("cannot print term"); + } + return Error(format("%1%, in `%2%'") % f.str() % (string) s); }