qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/4] rtc: fix 12-hour mode
Date: Sun, 01 Jan 2012 16:53:01 +0200	[thread overview]
Message-ID: <4F00734D.8020008@redhat.com> (raw)
In-Reply-To: <1321898431-18449-2-git-send-email-pbonzini@redhat.com>

On 11/21/2011 08:00 PM, Paolo Bonzini wrote:
> Hours in 12-hour mode are in the 1-12 range, not 0-11.
>
> @@ -320,7 +324,8 @@ static void rtc_copy_date(RTCState *s)
>          s->cmos_data[RTC_HOURS] = rtc_to_bcd(s, tm->tm_hour);
>      } else {
>          /* 12 hour format */
> -        s->cmos_data[RTC_HOURS] = rtc_to_bcd(s, tm->tm_hour % 12);
> +        int h = (tm->tm_hour % 12) ? tm->tm_hour % 12 : 12;
> +        s->cmos_data[RTC_HOURS] = rtc_to_bcd(s, h);
>          if (tm->tm_hour >= 12)
>              s->cmos_data[RTC_HOURS] |= 0x80;
>      }

Nitpick, don't update patch on this account:

I dislike seeing int-to-bool conversion on anything that is not a
true/false or count value.  Things like if (has_some_property) or if
(!nr_items) read well and are easily understood.  But here, you're not
checking for "are there any tm_hours, if yes, use them, if not, use
12".  You're testing against the value 0 which has a special encoding in
12 hour mode.

The is usually manifested in

   if (!strcmp(a, b)) ...

strcmp() does not return a bool or a count, and in fact it reads exactly
the opposite of the intent: "if not string compare".  strcmp() returns
an enumeration, or perhaps a mapping of string trichotomy to integer
trichotomy.

Sorry about the pontification, back to the regularly scheduled
whitespace discussion.

-- 
error compiling committee.c: too many arguments to function

  parent reply	other threads:[~2012-01-01 14:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-21 18:00 [Qemu-devel] [PATCH 0/4] Fixes to the rtc device model Paolo Bonzini
2011-11-21 18:00 ` [Qemu-devel] [PATCH 1/4] rtc: fix 12-hour mode Paolo Bonzini
2011-11-22  6:39   ` Mark Wu
2011-11-22  7:30     ` Paolo Bonzini
2012-01-01 14:53   ` Avi Kivity [this message]
2012-01-01 19:53     ` Paolo Bonzini
2011-11-21 18:00 ` [Qemu-devel] [PATCH 2/4] rtc: raise AF bit when the alarm is encountered but AIE=0 Paolo Bonzini
2011-11-21 18:00 ` [Qemu-devel] [PATCH 3/4] rtc: raise PF bit when the periodic timer triggers but PIE=0 Paolo Bonzini
2011-11-21 18:00 ` [Qemu-devel] [PATCH 4/4] rtc: clear non-PF bits when reinjecting on ack Paolo Bonzini
2011-12-30 15:58 ` [Qemu-devel] [PATCH 0/4] Fixes to the rtc device model Paolo Bonzini
2012-01-13 15:54   ` Paolo Bonzini
2012-01-13 16:54 ` Anthony Liguori

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=4F00734D.8020008@redhat.com \
    --to=avi@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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;
as well as URLs for NNTP newsgroup(s).