qemu-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-commits] [qemu/qemu] d17008: hw/timer/hpet.c: Avoid signed integer


From: GitHub
Subject: [Qemu-commits] [qemu/qemu] d17008: hw/timer/hpet.c: Avoid signed integer overflow whi...
Date: Mon, 09 Nov 2015 08:30:06 -0800

  Branch: refs/heads/master
  Home:   https://github.com/qemu/qemu
  Commit: d17008bc2914d62fd0af6a8f313604ae9f9a102c
      
https://github.com/qemu/qemu/commit/d17008bc2914d62fd0af6a8f313604ae9f9a102c
  Author: Peter Maydell <address@hidden>
  Date:   2015-11-09 (Mon, 09 Nov 2015)

  Changed paths:
    M hw/timer/hpet.c

  Log Message:
  -----------
  hw/timer/hpet.c: Avoid signed integer overflow which results in bugs on OSX

Signed integer overflow in C is undefined behaviour, and the compiler
is at liberty to assume it can never happen and optimize accordingly.
In particular, the subtractions in hpet_time_after() and hpet_time_after64()
were causing OSX clang to optimize the code such that it was prone to
hangs and complaints about the main loop stalling (presumably because
we were spending all our time trying to service very high frequency
HPET timer callbacks). The clang sanitizer confirms the UB:

hw/timer/hpet.c:119:26: runtime error: signed integer overflow: -2146967296 - 
2147003978 cannot be represented in type 'int'

Fix this by doing the subtraction as an unsigned operation and then
converting to signed for the comparison.

Reported-by: Aaron Elkins <address@hidden>
Cc: address@hidden
Signed-off-by: Peter Maydell <address@hidden>
Message-id: address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]