C - 瓦尔格林德报告"Syscall param points to uninitialised byte"时 sigqueue 调用



有一个程序,子进程需要向父亲发送一些信号。然而,瓦尔格林德在sigqueue呼叫中大喊大叫。已经阅读了一段时间,但我找不到答案。

以下是子进程的作用:

void cajero(int id){
    FILE *fp, *fp_caja;
    char filename[MAXBUFF], filename_caja[MAXBUFF], price[8];
    float p;
    union sigval val;
    bool booleano;
    ...
    val.sival_int = id;
    while(fgets(price, sizeof(price), fp)){
        p = atof(price);
        ...
        sigqueue(getppid(), SIGMONEY, val); //sigqueue Call
    }
    ...
    sigqueue(getppid(), SIGDONE, val); //sigqueue Call
    fclose(fp);
    exit(EXIT_SUCCESS);
}

这是一个孩子的valgrind报告(它在内部sigqueue中进行两次调用,在外部进行一次调用:

==14688== HEAP SUMMARY:
==14688==     in use at exit: 0 bytes in 0 blocks
==14688==   total heap usage: 48 allocs, 48 frees, 107,460 bytes allocated
==14688== 
==14688== All heap blocks were freed -- no leaks are possible
==14688== 
==14688== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 0 from 0)
==14688== 
==14688== 1 errors in context 1 of 2:
==14688== Syscall param rt_sigqueueinfo(uinfo) points to uninitialised byte(s)
==14688==    at 0x508DBE4: sigqueue (sigqueue.c:43)
==14688==    by 0x401B3A: cajero (ejercicio9.c:316)
==14688==    by 0x40130C: main (ejercicio9.c:181)
==14688==  Address 0xffefff67c is on thread 1's stack
==14688==  in frame #0, created by sigqueue (sigqueue.c:30)
==14688==  Uninitialised value was created by a stack allocation
==14688==    at 0x4018D7: cajero (ejercicio9.c:284)
==14688== 
==14688== 
==14688== 2 errors in context 2 of 2:
==14688== Syscall param rt_sigqueueinfo(uinfo) points to uninitialised byte(s)
==14688==    at 0x508DBE4: sigqueue (sigqueue.c:43)
==14688==    by 0x401AC1: cajero (ejercicio9.c:311)
==14688==    by 0x40130C: main (ejercicio9.c:181)
==14688==  Address 0xffefff67c is on thread 1's stack
==14688==  in frame #0, created by sigqueue (sigqueue.c:30)
==14688==  Uninitialised value was created by a stack allocation
==14688==    at 0x4018D7: cajero (ejercicio9.c:284)
==14688== 
==14688== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 0 from 0)

提前谢谢。我现在脑残了。

编辑:SIGMONEY和SIGDONE分别是SIGRTMIN和SIGRTMIN+1。

你没有初始化"val"联合。只需更改声明:

union sigval val = {0};

最新更新