代码片段:
int secret_foo(void)
{
int key = get_secret();
/* use the key to do highly privileged stuff */
....
/* Need to clear the value of key on the stack before exit */
key = 0;
/* Any half decent compiler would probably optimize out the statement above */
/* How can I convince it not to do that? */
return result;
}
key
我需要在 ing之前从堆栈中清除变量的值return
(如代码所示)。
如果您好奇,这是一个实际的客户需求(嵌入式域)。