From ba50e4f1203ad5cc20b7ada2fce4da62ab195622 Mon Sep 17 00:00:00 2001 From: Rémy Oudompheng Date: Mon, 18 Mar 2013 20:11:11 +0100 Subject: runtime: fix tv_sec 32-bit overflows in sleep routines. Fixes #5063. R=golang-dev, minux.ma, rsc CC=golang-dev https://golang.org/cl/7876043 --- src/pkg/runtime/os_linux.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/pkg/runtime/os_linux.c') diff --git a/src/pkg/runtime/os_linux.c b/src/pkg/runtime/os_linux.c index dc1e274378..8aa4c3d35d 100644 --- a/src/pkg/runtime/os_linux.c +++ b/src/pkg/runtime/os_linux.c @@ -36,15 +36,17 @@ void runtime·futexsleep(uint32 *addr, uint32 val, int64 ns) { Timespec ts, *tsp; + int64 secs; if(ns < 0) tsp = nil; else { - ts.tv_sec = ns/1000000000LL; - ts.tv_nsec = ns%1000000000LL; + secs = ns/1000000000LL; // Avoid overflow - if(ts.tv_sec > 1<<30) - ts.tv_sec = 1<<30; + if(secs > 1LL<<30) + secs = 1LL<<30; + ts.tv_sec = secs; + ts.tv_nsec = ns%1000000000LL; tsp = &ts; } -- cgit v1.3-5-g9baa