Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Also, as others have pointed out, even if the compiler would emit a warning, it would be way too much noise because such things happen all the time.

How so? For example, this code:

    printf("the pointer's value is %d", *p);
    free(p);
would not cause a warning under my proposal, even if free() contains a NULL check. The source code contains no unreachable lines, only the inlined/macroexpanded code does. On the other hand, most "gotcha" examples proposed so far do have unreachable source lines, and would lead to warnings.

Can you give an example of useful code that contains unreachable lines before macroexpansion and inlining? What's wrong with emitting a warning so the programmer can delete the useless line?

> You'll notice in a lot of cases that the exploitation of UB looks different for the same cases with different compilers or even compiler versions.

That's OK. The problem is with each individual compiler deleting code without warning. If compiler X deletes a line of my code, then it should warn me about it. If compiler Y doesn't delete that line, it doesn't have to warn me.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: