ioctl return 全局数组的错误地址

ioctl return bad address with global array

我正在根据这篇文章学习ALSA:http://equalarea.com/paul/alsa-audio.html#interruptex(A Minimal Interrupt-Driven Program)

注意short buf[4096];如果我们声明为全局的,会提示Bad address错误。如果我们声明它是int playback_callback (snd_pcm_sframes_t nframes)的local,它运行有时会提示Bad address错误。如果我们使用 malloc 分配 buf,错误就消失了。

正如我从 snd_pcm_writei 的源代码中看到的那样,它调用 ioctl 将缓冲区发送到设备。那么,为什么 ioctl 会像我描述的那样?

我正在使用 Ubuntu 14.04 64 位

那个程序有问题。

buf 有足够 space 用于 4096 个样本,但设备配置为每帧两个样本,因此 4096 帧将溢出缓冲区。