c-semantics icon indicating copy to clipboard operation
c-semantics copied to clipboard

kcc can't work with crackle

Open Lycbel opened this issue 7 years ago • 0 comments

#problem: kcc can compile the crackle project: https://github.com/mikeryan/crackle.git But the tests will all fail when gcc can work well

the cause: The problem will be introduced when passing the struct object`s address to callback function If change the value of the object in callback function, the value will be "reset" to original value after exit this function.

#testing platform information:

java: 
	java version "1.8.0_181"
	Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
	Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

ubuntu 16.04 on Vmware memory 5GB

kcc: 	kcc: version 1.0 GNU-compatible

	Build number: 07dcaa9-1541738973679
	Current profile: x86_64-linux-gcc-glibc
	Installed profiles: x86_64-linux-gcc-glibc-gnuc-reverse-eval-order
	                    x86_64-linux-gcc-glibc-gnuc
	                    x86_64-linux-gcc-glibc
	                    x86-gcc-limited-libc
	                    x86_64-linux-gcc-glibc-reverse-eval-order
	Default profile: x86_64-linux-gcc-glibc

make:
	GNU Make 4.1
	Built for x86_64-pc-linux-gnu
	Copyright (C) 1988-2014 Free Software Foundation, Inc.

to regenerate the whole problem:

wget https://github.com/Lycbel/cs510Files/blob/master/report6/crackle/crackle.zip?raw=true -O crackle.zip
unzip crackle.zip
cd crackle
bash runTotal.sh

in the folder unzipped above, it contains a minimized input: to run it (need to in the folder above)

cd mini
bash run.sh

the minimized input:

#include <pcap.h>
#include <stdio.h>
#include <stdlib.h>

/*
 * this is a minimized input for crackle https://github.com/mikeryan/crackle.git
 * kcc can compile the project, but it will fail all the tests, when gcc works correctly
 * the problem will be introduced when passing the struct object's address to callback function
 * if change the value of the object in callback function, the value will be 'reset' to original value after exit this function.
 */
struct Status{
    int i;
};
void my_callback(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet)
{
    struct Status * status;
    status = (struct Status *) useless;
    printf("sta->i=%d\n",status->i);
    //error will happend here
    // this is changing the value stored in original address. &(status->i) is same to &(statusInMain->i). but kcc won't change the value.
    status->i = 10;
}

int main(int argc,char **argv)
{
    //read the offline packets
    char errbuf[PCAP_ERRBUF_SIZE];
    pcap_t* descr;
    char* file = "./data.pcap";
    descr = pcap_open_offline(file,errbuf);
    if(descr == NULL) {
        printf("pcap_open_offline(): %s\n", errbuf);
        exit(1);
    }
    //handle each packet
    //sta is the struct passed into the callback function
    struct Status * statusInMain = malloc(sizeof(struct Status));
    pcap_dispatch(descr,0,my_callback,( u_char *)statusInMain);
    return 0;
}

out put:

-----------compile by kcc---------------
sta->i=0
sta->i=0
sta->i=0
sta->i=0
sta->i=0
sta->i=0
sta->i=0
sta->i=0
sta->i=0
sta->i=0
sta->i=0
sta->i=0
sta->i=0
sta->i=0
sta->i=0
-----------compile by gcc---------------
sta->i=0
sta->i=10
sta->i=10
sta->i=10
sta->i=10
sta->i=10
sta->i=10
sta->i=10
sta->i=10
sta->i=10
sta->i=10
sta->i=10
sta->i=10
sta->i=10
sta->i=10

Lycbel avatar Nov 26 '18 09:11 Lycbel