From ded7c51403aaee14faa3c231d53177e2b90bea30 Mon Sep 17 00:00:00 2001 From: hunt Date: Thu, 8 Sep 2005 19:13:57 +0000 Subject: 2005-09-08 Martin Hunt * arith.c (_stp_div64): Check for overflow. (_stp_mod64): Ditto. --- runtime/arith.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'runtime/arith.c') diff --git a/runtime/arith.c b/runtime/arith.c index e9977718..ee75e4f8 100644 --- a/runtime/arith.c +++ b/runtime/arith.c @@ -1,6 +1,7 @@ /* -*- linux-c -*- */ /* Math functions * Copyright (C) 2005 Red Hat Inc. + * Portions (C) Free Software Foundation, Inc. * * This file is part of systemtap, and is free software. You can * redistribute it and/or modify it under the terms of the GNU General @@ -30,8 +31,8 @@ long long _mod64 (long long u, long long v); int64_t _stp_div64 (const char **error, int64_t x, int64_t y) { #ifdef __LP64__ - if (unlikely (y == 0)) { - *error = "attempt to divide by 0"; + if (unlikely (y == 0 || (x == LONG_MIN && y == -1))) { + *error = "divisor out of range"; return 0; } return x/y; @@ -59,8 +60,8 @@ int64_t _stp_div64 (const char **error, int64_t x, int64_t y) int64_t _stp_mod64 (const char **error, int64_t x, int64_t y) { #ifdef __LP64__ - if (unlikely (y == 0)) { - *error = "attempt to divide by 0"; + if (unlikely (y == 0 || (x == LONG_MIN && y == -1))) { + *error = "divisor out of range"; return 0; } return x%y; -- cgit