summaryrefslogtreecommitdiffstats
path: root/toolkit/crashreporter/nsExceptionHandlerUtils.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/crashreporter/nsExceptionHandlerUtils.cpp
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/crashreporter/nsExceptionHandlerUtils.cpp')
-rw-r--r--toolkit/crashreporter/nsExceptionHandlerUtils.cpp51
1 files changed, 51 insertions, 0 deletions
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 <algorithm>
+
+#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;
+}