程序接收信号SIGSEGV,分段故障。当我打电话给scanf时

时间:2015-12-15 09:28:09

标签: linux gcc assembly scanf

每当我调用scanf时,我的程序都会超出界限。 我无法理解为什么。 请帮忙。

感谢。

.L2:
leal    -4(%esp)        ,%esp
leal    -4(%ebp)        ,%eax
pushl   %eax
pushl   readChar                #"%c"
call    scanf               #call scanf for the char

(gdb) info registers
 eax            0xffffced0  -12592 #the correct address of the place we want to insert the parameter

1 个答案:

答案 0 :(得分:2)

这是一个常见的错误。问题在于这个陈述

pushl   readChar

这会推送readChar中的long值,而不是readChar的地址。你需要的是:

pushl   $readChar

请注意美元符号(' $')。

相关问题