Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: James Courtier-Dutton <James@superbug.co.uk>
To: Sergey Vlasov <vsu@altlinux.ru>
Cc: "Kevin F.Quinn" <co@kevquinn.com>, alsa-devel@lists.sourceforge.net
Subject: Re: Re: alsa-lib patches
Date: Sun, 15 May 2005 20:04:08 +0100	[thread overview]
Message-ID: <42879D28.9060904@superbug.co.uk> (raw)
In-Reply-To: <20050515172102.GA13135@procyon.home>

Sergey Vlasov wrote:
> 
> mixer->pelems is an array of pointers to snd_mixer_elem_t, and qsort()
> passes pointers to array elements as arguments to the compare
> function - which becomes (snd_mixer_elem_t **).  But mixer->compare
> expects to get (snd_mixer_elem_t *) as arguments.
> 
Ok, so not a security issue, just a messed up pointer issue.


> However, seems that mixer elements have an indirect pointer to the
> mixer they belong to - elem->class->mixer.  So, how about this:
> 
> static int snd_mixer_qsort_compare(const void *a, const void *b)
> {
> 	snd_mixer_elem_t *elem_a = *(snd_mixer_elem_t **)a;
> 	snd_mixer_elem_t *elem_b = *(snd_mixer_elem_t **)b;
> 
> 	return elem_a->class->mixer->compare(elem_a, elem_b);
> }
> 
> static int snd_mixer_sort(snd_mixer_t *mixer)
> {
> 	unsigned int k;
> 	assert(mixer);
> 	assert(mixer->compare);
> 	INIT_LIST_HEAD(&mixer->elems);
> 	qsort(mixer->pelems, mixer->count, sizeof(snd_mixer_elem_t*), snd_mixer_qsort_compare);
> 	for (k = 0; k < mixer->count; k++)
> 		list_add_tail(&mixer->pelems[k]->list, &mixer->elems);
> 	return 0;
> }

That seems like a better solution. This sort routine does not have to be
high performance as it is not used often.

I suppose this begs the question, why has it work ok up until now?

James




-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click

  reply	other threads:[~2005-05-15 19:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-15 14:57 alsa-lib patches Kevin F.Quinn
2005-05-15 17:30 ` James Courtier-Dutton
2005-05-15 17:21   ` Sergey Vlasov
2005-05-15 19:04     ` James Courtier-Dutton [this message]
2005-05-15 20:24     ` Kevin F.Quinn
2005-05-15 20:34       ` Lee Revell
2005-05-15 22:15         ` Kevin F.Quinn
2005-05-15 22:33           ` Lee Revell
2005-05-16  8:53       ` Sergey Vlasov
2005-05-17  9:35       ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42879D28.9060904@superbug.co.uk \
    --to=james@superbug.co.uk \
    --cc=alsa-devel@lists.sourceforge.net \
    --cc=co@kevquinn.com \
    --cc=vsu@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox