don't NUL terminate when encoding
authorNot Zed <notzed@gmail.com>
Fri, 4 Dec 2020 05:33:26 +0000 (16:03 +1030)
committerNot Zed <notzed@gmail.com>
Fri, 4 Dec 2020 05:33:26 +0000 (16:03 +1030)
ez-blob-basic.c

index c0da23a..9378577 100644 (file)
@@ -177,8 +177,6 @@ void *ez_basic_decode(const ez_blob_desc *d, const ez_blob *blob) {
 
 int ez_basic_encode_raw(const ez_blob_desc *desc, const void *p, ez_blob *blob) {
        char *b = blob->eb_data;
-       size_t size = blob->eb_size;
-       char *be = b+size;
 
        for (int i=0,dlen=desc->bd_length;i<dlen;i++) {
                const ez_blob_desc *d = &desc[i+1];
@@ -226,9 +224,9 @@ int ez_basic_encode_raw(const ez_blob_desc *desc, const void *p, ez_blob *blob)
 
                                if (s) {
                                        size_t len = strlen(s);
+
                                        *(uint32_t *)b = len;
-                                       memcpy(b+4, s, len);
-                                       b[4+len] = 0;
+                                       memcpy(b + 4, s, len);
                                        b += 4 + len;
                                } else {
                                        *(uint32_t *)b = ~0U;
@@ -241,7 +239,8 @@ int ez_basic_encode_raw(const ez_blob_desc *desc, const void *p, ez_blob *blob)
                        abort();
                }
        }
-       assert(b == be);
+       if (b != blob->eb_size + blob->eb_data)
+               abort();
        return 0;
 }