ref: 6c80892463e0ae42dfd5bbce14adbaad1624ad93
parent: 8fda8a0adbb44f4e63bb86256d9f56700d79f301
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Jan 11 17:06:57 EST 2016
Don't sort or copy zero-length null arrays. It's sensible, but undefined.
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -283,7 +283,7 @@
if (val < 1ULL << (7*i))
break;
shift = 8 - i;
- b = ~0 << (shift + 1);
+ b = ~0ull << (shift + 1);
b |= val & ((1 << (8 - shift)) - 1);
fprintf(fd, "\t.byte %u\n", b);
val >>= shift;
--- a/parse/fold.c
+++ b/parse/fold.c
@@ -221,7 +221,8 @@
}
break;
case Oarr:
- qsort(n->expr.args, n->expr.nargs, sizeof(Node*), idxcmp);
+ if (n->expr.nargs > 0)
+ qsort(n->expr.args, n->expr.nargs, sizeof(Node*), idxcmp);
break;
case Ocast:
r = foldcast(n);
--- a/parse/util.c
+++ b/parse/util.c
@@ -116,6 +116,8 @@
{
void *ret;
+ if (!mem)
+ return NULL;
ret = xalloc(len);
return memcpy(ret, mem, len);
}