commit ee47da9c3992a846f3fb236e7796dbb88d44819c
Author: Mattias Andrée <[email protected]>
AuthorDate: Tue Mar 1 18:54:58 2016 +0100
Commit: Mattias Andrée <[email protected]>
CommitDate: Tue Mar 1 18:54:58 2016 +0100
Avoid using the internal structure as much as possible
Signed-off-by: Mattias Andrée <[email protected]>
diff --git a/src/zload.c b/src/zload.c
index 9e4521f..e03d911 100644
--- a/src/zload.c
+++ b/src/zload.c
@@ -17,8 +17,8 @@ zload(z_t a, const void *buffer)
} else {
a->chars = 0;
}
- if (a->sign) {
+ if (!zzero(a)) {
memcpy(a->chars, buf, a->used * sizeof(*(a->chars)));
}
- return sizeof(z_t) - sizeof(a->chars) + (a->sign ? a->used *
sizeof(*(a->chars)) : 0);
+ return sizeof(z_t) - sizeof(a->chars) + (zzero(a) ? 0 : a->used *
sizeof(*(a->chars)));
}
diff --git a/src/zsave.c b/src/zsave.c
index 6f68387..6aa50b5 100644
--- a/src/zsave.c
+++ b/src/zsave.c
@@ -12,9 +12,9 @@ zsave(z_t a, void *buffer)
*((int *)buf) = a->sign, buf += sizeof(int);
*((size_t *)buf) = a->used, buf += sizeof(size_t);
*((size_t *)buf) = a->alloced, buf += sizeof(size_t);
- if (a->sign) {
+ if (!zzero(a)) {
memcpy(buf, a->chars, a->used * sizeof(*(a->chars)));
}
}
- return sizeof(z_t) - sizeof(a->chars) + (a->sign ? a->used *
sizeof(*(a->chars)) : 0);
+ return sizeof(z_t) - sizeof(a->chars) + (zzero(a) ? 0 : a->used *
sizeof(*(a->chars)));
}