From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 13 21:00:52 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6295816A4D2 for ; Wed, 13 Oct 2004 21:00:52 +0000 (GMT) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id C355D43D3F for ; Wed, 13 Oct 2004 21:00:36 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.11/8.12.11) id i9DL0TYp007455; Wed, 13 Oct 2004 16:00:29 -0500 (CDT) (envelope-from dan) Date: Wed, 13 Oct 2004 16:00:29 -0500 From: Dan Nelson To: Shawn Webb Message-ID: <20041013210029.GA88757@dan.emsphone.com> References: <001201c4b224$fcd68320$65cfe404@shawns> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <001201c4b224$fcd68320$65cfe404@shawns> X-OS: FreeBSD 5.3-BETA7 X-message-flag: Outlook Error User-Agent: Mutt/1.5.6i cc: freebsd-hackers@freebsd.org Subject: Re: malloc calls and ioctl calls to soundcard cause segfault X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Oct 2004 21:00:52 -0000 In the last episode (Oct 14), Shawn Webb said: > I've got to rewrite the source due to hard disk problems, so I'll just put > it in this email: > > arg = FORMAT; > if (ioctl(fd, SNDCTL_DSP_SETFMT, &arg) < 0) > { > perror("ioctl setfmt"); > exit(1); > } > > if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &arg) < 0) > { > perror("ioctl getospace"); > exit(1); > } SNDCTL_DSP_GETOSPACE takes a pointer to an "audio_buf_info" type, so you actually asked it to write sizeof(audio_buf_info) bytes to the location of the "arg" variable, which is... (drumroll) on the stack :) Create another variable "audio_buf_info info;" above main, and change that call to "if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) < 0)" and your program will run fine. -- Dan Nelson dnelson@allantgroup.com