From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 14 01:50:50 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 E30DB16A4CE for ; Thu, 14 Oct 2004 01:50:50 +0000 (GMT) Received: from jive.SoftHome.net (jive.SoftHome.net [66.54.152.27]) by mx1.FreeBSD.org (Postfix) with SMTP id 730BC43D3F for ; Thu, 14 Oct 2004 01:50:50 +0000 (GMT) (envelope-from shawnwebb@softhome.net) Received: (qmail 32595 invoked by uid 417); 14 Oct 2004 01:37:01 -0000 Received: from mambo-.softhome.net (HELO softhome.net) (172.16.2.15) by shunt-smtp-out-0 with SMTP; 14 Oct 2004 01:37:01 -0000 Received: from localhost (localhost [127.0.0.1]) (uid 417) by softhome.net with local; Wed, 13 Oct 2004 19:37:00 -0600 References: <001201c4b224$fcd68320$65cfe404@shawns> <20041013210029.GA88757@dan.emsphone.com> In-Reply-To: <20041013210029.GA88757@dan.emsphone.com> From: shawnwebb@softhome.net To: Dan Nelson Date: Wed, 13 Oct 2004 19:36:59 -0600 Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Sender: shawnwebb@softhome.net X-Originating-IP: [198.179.147.18] Message-ID: 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: Thu, 14 Oct 2004 01:50:51 -0000 Thanks for pointing that out. The OSS documentation didn't go into detail about what type of arg was needed for getospace, so I assumed int. Dan Nelson writes: > 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 > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"