From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- toolkit/crashreporter/nsExceptionHandlerUtils.cpp | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 toolkit/crashreporter/nsExceptionHandlerUtils.cpp (limited to 'toolkit/crashreporter/nsExceptionHandlerUtils.cpp') diff --git a/toolkit/crashreporter/nsExceptionHandlerUtils.cpp b/toolkit/crashreporter/nsExceptionHandlerUtils.cpp new file mode 100644 index 0000000000..e7f70e599b --- /dev/null +++ b/toolkit/crashreporter/nsExceptionHandlerUtils.cpp @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsExceptionHandlerUtils.h" + +#include + +#include "double-conversion/double-conversion.h" + +// Format a non-negative double to a string, without using C-library functions, +// which need to be avoided (.e.g. bug 1240160, comment 10). Return false if +// we failed to get the formatting done correctly. +bool SimpleNoCLibDtoA(double aValue, char* aBuffer, int aBufferLength) { + // aBufferLength is the size of the buffer. Be paranoid. + aBuffer[aBufferLength - 1] = '\0'; + + if (aValue < 0) { + return false; + } + + int length, point, i; + bool sign; + bool ok = true; + double_conversion::DoubleToStringConverter::DoubleToAscii( + aValue, double_conversion::DoubleToStringConverter::SHORTEST, 8, aBuffer, + aBufferLength, &sign, &length, &point); + + // length does not account for the 0 terminator. + if (length > point && (length + 1) < (aBufferLength - 1)) { + // We have to insert a decimal point. Not worried about adding a leading + // zero in the < 1 (point == 0) case. + aBuffer[length + 1] = '\0'; + for (i = length; i > std::max(point, 0); i -= 1) { + aBuffer[i] = aBuffer[i - 1]; + } + aBuffer[i] = '.'; // Not worried about locales + } else if (length < point) { + // Trailing zeros scenario + for (i = length; i < point; i += 1) { + if (i >= aBufferLength - 2) { + ok = false; + } + aBuffer[i] = '0'; + } + aBuffer[i] = '\0'; + } + return ok; +} -- cgit v1.2.3