This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
以下是一些不确定行为的好候选人:
如果
大小
太大,则说明数百万,用自动存储分配的阵列可能会导致 stack Overflow 。如果用户输入的
size
大于128,则将数组转换为字符串的代码可能会导致缓冲区溢出,从而导致不确定的行为。在子进程中:
addr
指向内存映射的文件内容。该文件不包含零件终结器,因此,如果偶然的大小是页面大小的倍数,则内存映射块将不包含null终结器,puts(addr)
将读取块,导致不确定的行为。请注意,以上都不会导致该过程在第一个
printf
调用之前失败。Here are a few good candidates for undefined behavior:
If
size
is too large, say greater than a few millions, the array allocated with automatic storage will likely cause a stack overflow.If
size
entered by the user is larger than 128, the code converting the array to a string will likely cause a buffer overflow causing undefined behavior.In the child process:
addr
points to the memory mapped file contents. This file does not contain a null terminator, hence if by chance its size is a multiple of the page size, the memory mapped block will not contain a null terminator andputs(addr)
will read beyond the end of the block, causing undefined behavior.Note that none of the above may cause the process to fail before the first
printf
call.