alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* bug report: aloop: potential signedness bug in loopback_prepare()
@ 2010-10-09 11:42 Dan Carpenter
  2010-10-09 12:14 ` Jaroslav Kysela
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2010-10-09 11:42 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: alsa-devel

Hi Jaroslav,

sound/drivers/aloop.c +287 loopback_prepare(10)
	warn: bogus compare against zero: 'bps'
   282          unsigned int bps, salign;
   283
   284          salign = (snd_pcm_format_width(runtime->format) *
   285							runtime->channels) / 8;
   286          bps = salign * runtime->rate;
   287          if (bps <= 0 || salign <= 0)
                    ^^^^^^^^^^^^^^^^^^^^^^^

	Both "bps" and "salign" are unsigned and are never less than
	zero.  Should this just be checking for == 0?  Or was the check
	supposed to catch integer overflows?

   288                  return -EINVAL;
   289

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bug report: aloop: potential signedness bug in loopback_prepare()
  2010-10-09 11:42 bug report: aloop: potential signedness bug in loopback_prepare() Dan Carpenter
@ 2010-10-09 12:14 ` Jaroslav Kysela
  2010-10-09 14:58   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Jaroslav Kysela @ 2010-10-09 12:14 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: ALSA development

On Sat, 9 Oct 2010, Dan Carpenter wrote:

> Hi Jaroslav,
>
> sound/drivers/aloop.c +287 loopback_prepare(10)
> 	warn: bogus compare against zero: 'bps'
>   282          unsigned int bps, salign;
>   283
>   284          salign = (snd_pcm_format_width(runtime->format) *
>   285							runtime->channels) / 8;
>   286          bps = salign * runtime->rate;
>   287          if (bps <= 0 || salign <= 0)
>                    ^^^^^^^^^^^^^^^^^^^^^^^
>
>
> 	Both "bps" and "salign" are unsigned and are never less than
> 	zero.  Should this just be checking for == 0?  Or was the check
> 	supposed to catch integer overflows?

The condition works for both signed and unsigned values. That was only 
reason why I did not write '==' there.

 					Jaroslav

-----
Jaroslav Kysela <perex@perex.cz>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bug report: aloop: potential signedness bug in loopback_prepare()
  2010-10-09 12:14 ` Jaroslav Kysela
@ 2010-10-09 14:58   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2010-10-09 14:58 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: ALSA development

On Sat, Oct 09, 2010 at 02:14:30PM +0200, Jaroslav Kysela wrote:
> On Sat, 9 Oct 2010, Dan Carpenter wrote:
>
>> Hi Jaroslav,
>>
>> sound/drivers/aloop.c +287 loopback_prepare(10)
>> 	warn: bogus compare against zero: 'bps'
>>   282          unsigned int bps, salign;
>>   283
>>   284          salign = (snd_pcm_format_width(runtime->format) *
>>   285							runtime->channels) / 8;
>>   286          bps = salign * runtime->rate;
>>   287          if (bps <= 0 || salign <= 0)
>>                    ^^^^^^^^^^^^^^^^^^^^^^^
>>
>>
>> 	Both "bps" and "salign" are unsigned and are never less than
>> 	zero.  Should this just be checking for == 0?  Or was the check
>> 	supposed to catch integer overflows?
>
> The condition works for both signed and unsigned values. That was only  
> reason why I did not write '==' there.
>
> 					Jaroslav
>

What I mean is that the less than zero part is never true.  For example,
the following test program will print "more" instead of "less".

regards,
dan carpenter

#include <stdio.h>

int main(int argc, char **argv)
{
	unsigned int x = -3;

	if (x <= 0)
		printf("less\n");
	else
		printf("more\n");

	return 0;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-10-09 14:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-09 11:42 bug report: aloop: potential signedness bug in loopback_prepare() Dan Carpenter
2010-10-09 12:14 ` Jaroslav Kysela
2010-10-09 14:58   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).