From patchwork Thu Oct 31 18:25:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 178215 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3227283ill; Thu, 31 Oct 2019 11:25:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1YhV6Cw+hkEv20ymOZeg/83hP8AiHl3hgWhsuFE6G4K+rTIr86g8H2WMlbBylbVA20Mdx X-Received: by 2002:aa7:c954:: with SMTP id h20mr7798541edt.159.1572546346712; Thu, 31 Oct 2019 11:25:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572546346; cv=none; d=google.com; s=arc-20160816; b=z7Fun7rHChyxD8rfX3fYX7uM+OcJ1tvBFOQFmrdSdptTyVvYJ4c2oaSLd5UTqog2N7 XOSygqRZFC9s2NH5JUh+xyGxoZ8MXy2DBUvkgvY+1xqFkQJGgQmND5DTUnFLKUcbp7Md fzE8NjmN0/862dZqoN6Hd+3jLTQCmxkZGKMo7yd11333Yy/vWJR6FCzhiud0Jv4KFBX0 neWCMJ0LnecyLaN1Ii8wBq+5ZdItq0DY9K/vB7aBmXUbpJ4DnfG07narkbGFFXK1rI2J xfdqZPseiOd0cVKQxdrHEwpCnyy+XQHi6/5wSDbQJWbDNiPYLq2jSxlrPUOwstWFKcll E3cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=Y618HyA1TnzAMy8wXzGF4AhHa/5YE8D8PP91XLm5plM=; b=0ZgN56vl3PdAucZWFi54whrDYxM1dXC0StZrLhzhw5O31bXyVmFr1ckFpoYWfybo1p NGwRHDfLUUNcePngA3ooc8/0YngM+A10Y59Zj4hdlsia97dvTC9Y+mqsntdIN6xWzxL+ v/KvrmT0CU0XtGhZJfSw4y/ZyDHls4SEX1mxZD2N+nUnpAo39zxaT8arR1i6UvX5xF5l e8NQAn0yLR3qpElhQlZ3ynjhMlIY+ev3lQk0rrpL2WfA3+sbiMPl0jNQZ8yQInKOMKXu 7P7CG6cygyK9CIoa3vzEBA5oIN2HL4JcsOPV5lcqRx3A3mfRYvNxvrV2XPFay4exTzSa Ov5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=NK3UbKhr; dkim=pass header.i=@linaro.org header.s=google header.b=PzOpfDcN; spf=pass (google.com: domain of libc-alpha-return-106506-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-106506-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id g28si4818595edg.327.2019.10.31.11.25.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Oct 2019 11:25:46 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-106506-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=NK3UbKhr; dkim=pass header.i=@linaro.org header.s=google header.b=PzOpfDcN; spf=pass (google.com: domain of libc-alpha-return-106506-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-106506-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=wpknFf/xRhH4II5zRvKrleJ7FkY5dUN GbBlz4SCB1evWHPopilt92J/46V6985SkGtZ/jYkTmhb4pbQdiNpqYN/j4slYAmD JIQA/MaXb2jIjIgSfUERh/NuhmuWy96bJsHU8zN2EgfFlIMyjF1yY70DhZ532tuF XTZPp8dQJlC4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=hWclRAODTTa21xij7AGWQriNqeo=; b=NK3Ub KhrwjQ6KaoURdnXhZWqI2qiGa1g05eKzpokjnh9ivX5eMuAsvHWCSdJYtxNZPi9Y JNwqH79Ukopa9D2UJ6VKaJa5gnroTKUm8WUjtJZ9iz4Kgyt2d2OYO64rR01MrehW VhOtDWWa1XpzOoNko9QGf/IFWMioVdLxqMVlOQ= Received: (qmail 25326 invoked by alias); 31 Oct 2019 18:25:37 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 25229 invoked by uid 89); 31 Oct 2019 18:25:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qk1-f196.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=Y618HyA1TnzAMy8wXzGF4AhHa/5YE8D8PP91XLm5plM=; b=PzOpfDcNoGhX46MdZptSNCu+AHMXGpB9FPe34yX5pXud4C0DXJ7C2EL5yoXgKioWhu 7vbw8ERNWpjSpVl8q6DyaCP9Iy1puzTU//bKbOMyBDivRfdCmIR72himXHEJIxsKQaXM 9VutDq8epVKKJrBwvdlO0/MNTq4CiCUjinXg/RJIrQSVEu4YuNcviMJW0+EAeABm1/iO lFzkqXYTD3yPkkdoMegGxnN11AVbw1Kc1NBkmqbwUldIGoBzPL587CII1jXlFaggfPUP 5XkloOdcL9H7Ajb0EdoooPttfklNkanMY17zMH3sSL04Xm91v2tRvZdP1FR4mpvSQIt/ 2WlQ== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 2/2] Sync timespec-{add,sub} with gnulib Date: Thu, 31 Oct 2019 15:25:27 -0300 Message-Id: <20191031182527.26933-2-adhemerval.zanella@linaro.org> In-Reply-To: <20191031182527.26933-1-adhemerval.zanella@linaro.org> References: <20191031182527.26933-1-adhemerval.zanella@linaro.org> It sync with gnulib commit 06011ed74e978613422aca43c0bd92dc44213933. --- support/timespec-add.c | 20 +++++++------------- support/timespec-sub.c | 20 +++++++------------- 2 files changed, 14 insertions(+), 26 deletions(-) -- 2.17.1 diff --git a/support/timespec-add.c b/support/timespec-add.c index ea9791dc9f..8efb8a6eb6 100644 --- a/support/timespec-add.c +++ b/support/timespec-add.c @@ -33,36 +33,30 @@ timespec_add (struct timespec a, struct timespec b) int ns = a.tv_nsec + b.tv_nsec; int nsd = ns - TIMESPEC_HZ; int rns = ns; - time_t tmin = TYPE_MINIMUM (time_t); - time_t tmax = TYPE_MAXIMUM (time_t); if (0 <= nsd) { rns = nsd; - if (bs < tmax) - bs++; + time_t bs1; + if (!INT_ADD_WRAPV (bs, 1, &bs1)) + bs = bs1; else if (rs < 0) rs++; else goto high_overflow; } - /* INT_ADD_WRAPV is not appropriate since time_t might be unsigned. - In theory time_t might be narrower than int, so plain - INT_ADD_OVERFLOW does not suffice. */ - if (! INT_ADD_OVERFLOW (rs, bs) && tmin <= rs + bs && rs + bs <= tmax) - rs += bs; - else + if (INT_ADD_WRAPV (rs, bs, &rs)) { - if (rs < 0) + if (bs < 0) { - rs = tmin; + rs = TYPE_MINIMUM (time_t); rns = 0; } else { high_overflow: - rs = tmax; + rs = TYPE_MAXIMUM (time_t); rns = TIMESPEC_HZ - 1; } } diff --git a/support/timespec-sub.c b/support/timespec-sub.c index 0fe6517109..cf16ed7832 100644 --- a/support/timespec-sub.c +++ b/support/timespec-sub.c @@ -33,36 +33,30 @@ timespec_sub (struct timespec a, struct timespec b) time_t bs = b.tv_sec; int ns = a.tv_nsec - b.tv_nsec; int rns = ns; - time_t tmin = TYPE_MINIMUM (time_t); - time_t tmax = TYPE_MAXIMUM (time_t); if (ns < 0) { rns = ns + TIMESPEC_HZ; - if (bs < tmax) - bs++; + time_t bs1; + if (!INT_ADD_WRAPV (bs, 1, &bs1)) + bs = bs1; else if (- TYPE_SIGNED (time_t) < rs) rs--; else goto low_overflow; } - /* INT_SUBTRACT_WRAPV is not appropriate since time_t might be unsigned. - In theory time_t might be narrower than int, so plain - INT_SUBTRACT_OVERFLOW does not suffice. */ - if (! INT_SUBTRACT_OVERFLOW (rs, bs) && tmin <= rs - bs && rs - bs <= tmax) - rs -= bs; - else + if (INT_SUBTRACT_WRAPV (rs, bs, &rs)) { - if (rs < 0) + if (0 < bs) { low_overflow: - rs = tmin; + rs = TYPE_MINIMUM (time_t); rns = 0; } else { - rs = tmax; + rs = TYPE_MAXIMUM (time_t); rns = TIMESPEC_HZ - 1; } }