c99 goto past initialization

后端 未结 7 1971
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 07:34

While debugging a crash, I came across this issue in some code:

int func()
{
    char *p1 = malloc(...);
    if (p1 == NULL)
        goto err_exit;

    char         


        
7条回答
  •  無奈伤痛
    2020-11-30 08:21

    if i compile this code with -O2 flag

    gcc -Wall -std=c99 -O2 jump.c
    

    i've got warning:

    jump.c: In function ‘func’:
    jump.c:10: warning: ‘p2’ may be used uninitialised in this function
    

    and no warning without optimization

提交回复
热议问题