All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Poole <mdpoole@troilus.org>
To: ext-phil.2.carmody@nokia.com
Cc: chase.douglas@canonical.com, pinglinux@gmail.com,
	jkosina@suse.cz, linux-input@vger.kernel.org
Subject: Re: [PATCH] hid-magicmouse: Correct parsing of large X and Y motions.
Date: Tue, 06 Jul 2010 07:55:12 -0400	[thread overview]
Message-ID: <87lj9oakpr.fsf@troilus.org> (raw)
In-Reply-To: <702744BC498BAE41B3AA631D95EC463058B3CFD77F@NOK-EUMSG-01.mgdnok.nokia.com> (ext-phil's message of "Tue, 6 Jul 2010 13:23:03 +0200")

ext-phil.2.carmody@nokia.com writes:

[snip]
>>+/* Function shamelessly borrowed from hid-core.c. */
>>+
>>+static s32 snto32(__u32 value, unsigned n)
>>+{
>>+       switch (n) {
>>+       case 8:  return ((__s8)value);
>>+       case 16: return ((__s16)value);
>>+       case 32: return ((__s32)value);
>
> Beware - this relies on sane behaviour from the current and future compilers, as the C standard doesn't mandate what should happen when shortening out of range signed values. [n869.txt: 6.3.1.1.#3]

That's good to know.  There's probably some much more complicated, but
portable, way to write the operation -- I suspect we'll continue to rely
on the compiler to be sane.

>>+       }
>>+       return value & (1 << (n - 1)) ? value | (-1 << n) : value;
>
> That signed left shift, however, is good old fashioned undefined behaviour. [n869.txt 6.5.7.#4]

Which version is that from?  The copy of C99 I have says the resulting
value is -1 * (2 ** n) if that value can be represented.  (A 6 May 2005
committee draft of TC2 says the same thing.)  Until n > 31, the behavior
should be standard-defined.

Michael

  parent reply	other threads:[~2010-07-06 11:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-05 14:50 [PATCH] hid-magicmouse: Correct parsing of large X and Y motions Michael Poole
2010-07-05 16:28 ` Chase Douglas
2010-07-11 21:07   ` Jiri Kosina
2010-07-05 19:54 ` Ping Cheng
2010-07-05 20:02   ` Chase Douglas
2010-07-05 20:33     ` Michael Poole
2010-07-05 20:51       ` Chase Douglas
2010-07-05 22:08         ` Michael Poole
2010-07-05 22:25           ` Chase Douglas
2010-07-06 11:23           ` ext-phil.2.carmody
2010-07-06 11:38             ` Datta, Shubhrajyoti
2010-07-06 11:55             ` Michael Poole [this message]
2010-07-06 13:05               ` ext-phil.2.carmody
2010-07-05 22:51   ` Dmitry Torokhov

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=87lj9oakpr.fsf@troilus.org \
    --to=mdpoole@troilus.org \
    --cc=chase.douglas@canonical.com \
    --cc=ext-phil.2.carmody@nokia.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=pinglinux@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.