From 1017fc5c1af764f55133f7b23f102428bb1d37c0 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Thu, 14 Apr 2016 04:50:44 +0300 Subject: [PATCH] Fix the digit counting helpers to take into account negative values. --- source/Library/Math.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Library/Math.cpp b/source/Library/Math.cpp index 3b6bf612..49ec51cb 100644 --- a/source/Library/Math.cpp +++ b/source/Library/Math.cpp @@ -1075,7 +1075,7 @@ static SQInteger SqDigits1(HSQUIRRELVM vm) return sq_throwerror(vm, "Wrong number of arguments"); } // Fetch the integer value from the stack - Int64 n = PopStackLong(vm, 2); + Int64 n = std::llabs(PopStackLong(vm, 2)); // Start with 0 digits Uint8 d = 0; // Identify the number of digits @@ -1099,7 +1099,7 @@ static SQInteger SqDigits0(HSQUIRRELVM vm) return sq_throwerror(vm, "Wrong number of arguments"); } // Fetch the integer value from the stack - Int64 n = PopStackLong(vm, 2); + Int64 n = std::llabs(PopStackLong(vm, 2)); // Start with 0 digits Uint8 d = 0; // Identify the number of digits