Skip to content
Browse files

fix the most obvious extcap bugs

  • Loading branch information...
1 parent e11128d commit 9275422a9e80e8a263e4cd6864e5ec79ba32d756 @mauke committed Mar 27, 2012
Showing with 14 additions and 5 deletions.
  1. +14 −5 unibilium.c
View
19 unibilium.c
@@ -139,6 +139,8 @@ unibi_term *unibi_dummy(void) {
DYNARR(str, init)(&t->ext_names);
t->ext_alloc = NULL;
+ ASSERT_EXT_NAMES(t);
+
return t;
}
@@ -370,6 +372,7 @@ unibi_term *unibi_from_mem(const char *p, size_t n) {
DEL_FAIL_IF(v < 0 || (unsigned short)v >= tblsz2, EINVAL, t);
t->ext_names.data[i] = ext_alloc2 + v;
}
+ t->ext_names.used = extalllen;
p += extalllen * 2;
n -= extalllen * 2;
@@ -386,6 +389,8 @@ unibi_term *unibi_from_mem(const char *p, size_t n) {
}
}
+ ASSERT_EXT_NAMES(t);
+
return t;
}
@@ -621,12 +626,16 @@ size_t unibi_dump(const unibi_term *t, char *ptr, size_t n) {
for (i = 0; i < t->ext_strs.used; i++) {
const char *const s = t->ext_strs.data[i];
- const size_t k = strlen(s) + 1;
- assert(off < MAX15BITS);
- put_ushort(p, off);
+ if (!s) {
+ put_short(p, -1);
+ } else {
+ const size_t k = strlen(s) + 1;
+ assert(off < MAX15BITS);
+ put_ushort(p, off);
+ memcpy(tbl1 + off, s, k);
+ off += k;
+ }
p += 2;
- memcpy(tbl1 + off, s, k);
- off += k;
}
assert(off == ext_tablsz1);

0 comments on commit 9275422

Please sign in to comment.
Something went wrong with that request. Please try again.