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

Wrong value when passing "struct stat" as a parameter to a function #37

Open
xjtuwxg opened this issue Aug 7, 2018 · 0 comments
Open

Comments

@xjtuwxg
Copy link
Member

xjtuwxg commented Aug 7, 2018

Problem description

Hi I got this simple test file when debugging the issue 36:

#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>       // struct stat
#include <fcntl.h>          // O_RDONLY

void print_stat(struct stat sbuf)
//void print_stat(struct stat *sbuf)
{
    printf(">> stat sbuf.st_mode: 0x%x\n", sbuf.st_mode);
    //printf("stat sbuf.st_mode: 0x%x\n", sbuf->st_mode);
}

int main(int argc, char *argv[])
{
    struct stat sbuf;
    int fd = open("fstat.c", O_RDONLY, 0);
    if (fd < 0) {
        printf("error");
        return 1;
    }
    fstat(fd, &sbuf);
    printf("stat sbuf.st_mode: 0x%x\n", sbuf.st_mode);
    printf("sizeof(struct stat): %lu, %lu\n", sizeof(sbuf), sizeof(struct stat));
    print_stat(sbuf);
    //print_stat(&sbuf);
    close(fd);
    return 0;
}

For some reason, it has the following results (the value of st_mode is changed):

$ ./2_x86-64
stat sbuf.st_mode: 0x81a4
sizeof(struct stat): 128, 128
>> stat sbuf.st_mode: 0x3a297461

Environment

popcorn-compiler: from commit 4ffd16e, patched with the code from issue 36.

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

No branches or pull requests

1 participant