Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hard to detect bug when capn_setp not called. #8

Open
slayercat opened this issue Jun 12, 2016 · 1 comment
Open

hard to detect bug when capn_setp not called. #8

slayercat opened this issue Jun 12, 2016 · 1 comment

Comments

@slayercat
Copy link

slayercat commented Jun 12, 2016

If capn_setp not been called. data serialized shell not contain it. or an assert shell emit at least.

It's really hard to debug it.

eg.

file a.capnp

@0xb5c2cbd0a1ee9f74;

struct Person{
    name @0 :Text;
}

#include <unistd.h>
#include<sys/types.h>
#include<fcntl.h>
#include <capnp_c.h>

#include "a.capnp.h"


void x(){

};

int main() {
    struct capn capn;
    struct capn_segment *seg;
    capn_init_malloc(&capn);
    capn_ptr root = capn_root(&capn);
    Person_ptr personobj=new_Person(root.seg);
    printf("root->type %d\n",root.type);
    struct capn_text ustr={
        3,"aaa", NULL
    };  
    Person_set_name(personobj, ustr);
    int fd=open("aaa.data",O_CREAT|O_RDWR);
    capn_write_fd(&capn, write , fd, 0); 
    close(fd);
}

this will generate file aaa.data, content:

[root@7e6235426e5d bbb]# od -x aaa.data 
0000000 0000 0000 0003 0000 0000 0000 0000 0000
0000020 0001 0000 0022 0000 6161 0061 0000 0000
0000040
[root@7e6235426e5d bbb]# capnp decode a.capnp Person < aaa.data 
()

[root@7e6235426e5d test-go-capnp]# od -x good.data
0000000 0000 0000 0003 0000 0000 0000 0000 0001
0000020 0001 0000 0022 0000 6161 0061 0000 0000
0000040
[root@7e6235426e5d test-go-capnp]# capnp decode a.capnp Person < good.data 
(name = "aaa")

@eqvinox
Copy link

eqvinox commented Jun 22, 2016

Hm. Need to look at this in more detail...

Warning probably needs to be on unused data, not on a "null" pointer - null pointers are useful and explicitly desirable in some situations, but here there is data allocated that isn't used. Not sure how & where to do this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants