Bug 1890689 remove DynamicResampler::mSetBufferDuration r=pehrsons
[gecko.git] / toolkit / crashreporter / nsExceptionHandlerUtils.cpp
blobe7f70e599ba5ce2dac85178c0c9a46f25de6cff3
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsExceptionHandlerUtils.h"
9 #include <algorithm>
11 #include "double-conversion/double-conversion.h"
13 // Format a non-negative double to a string, without using C-library functions,
14 // which need to be avoided (.e.g. bug 1240160, comment 10). Return false if
15 // we failed to get the formatting done correctly.
16 bool SimpleNoCLibDtoA(double aValue, char* aBuffer, int aBufferLength) {
17 // aBufferLength is the size of the buffer. Be paranoid.
18 aBuffer[aBufferLength - 1] = '\0';
20 if (aValue < 0) {
21 return false;
24 int length, point, i;
25 bool sign;
26 bool ok = true;
27 double_conversion::DoubleToStringConverter::DoubleToAscii(
28 aValue, double_conversion::DoubleToStringConverter::SHORTEST, 8, aBuffer,
29 aBufferLength, &sign, &length, &point);
31 // length does not account for the 0 terminator.
32 if (length > point && (length + 1) < (aBufferLength - 1)) {
33 // We have to insert a decimal point. Not worried about adding a leading
34 // zero in the < 1 (point == 0) case.
35 aBuffer[length + 1] = '\0';
36 for (i = length; i > std::max(point, 0); i -= 1) {
37 aBuffer[i] = aBuffer[i - 1];
39 aBuffer[i] = '.'; // Not worried about locales
40 } else if (length < point) {
41 // Trailing zeros scenario
42 for (i = length; i < point; i += 1) {
43 if (i >= aBufferLength - 2) {
44 ok = false;
46 aBuffer[i] = '0';
48 aBuffer[i] = '\0';
50 return ok;