/src/mozilla-central/toolkit/crashreporter/nsExceptionHandlerUtils.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "nsExceptionHandlerUtils.h" |
8 | | |
9 | | #include "double-conversion/double-conversion.h" |
10 | | |
11 | | // Format a non-negative double to a string, without using C-library functions, |
12 | | // which need to be avoided (.e.g. bug 1240160, comment 10). Return false if |
13 | | // we failed to get the formatting done correctly. |
14 | | bool SimpleNoCLibDtoA(double aValue, char* aBuffer, int aBufferLength) |
15 | 0 | { |
16 | 0 | // aBufferLength is the size of the buffer. Be paranoid. |
17 | 0 | aBuffer[aBufferLength-1] = '\0'; |
18 | 0 |
|
19 | 0 | if (aValue < 0) { |
20 | 0 | return false; |
21 | 0 | } |
22 | 0 | |
23 | 0 | int length, point, i; |
24 | 0 | bool sign; |
25 | 0 | bool ok = true; |
26 | 0 | double_conversion::DoubleToStringConverter::DoubleToAscii( |
27 | 0 | aValue, |
28 | 0 | double_conversion::DoubleToStringConverter::SHORTEST, |
29 | 0 | 8, |
30 | 0 | aBuffer, |
31 | 0 | aBufferLength, |
32 | 0 | &sign, |
33 | 0 | &length, |
34 | 0 | &point); |
35 | 0 |
|
36 | 0 | // length does not account for the 0 terminator. |
37 | 0 | if (length > point && (length+1) < (aBufferLength-1)) { |
38 | 0 | // We have to insert a decimal point. Not worried about adding a leading zero |
39 | 0 | // in the < 1 (point == 0) case. |
40 | 0 | aBuffer[length+1] = '\0'; |
41 | 0 | for (i=length; i>point; i-=1) { |
42 | 0 | aBuffer[i] = aBuffer[i-1]; |
43 | 0 | } |
44 | 0 | aBuffer[i] = '.'; // Not worried about locales |
45 | 0 | } else if (length < point) { |
46 | 0 | // Trailing zeros scenario |
47 | 0 | for (i=length; i<point; i+=1) { |
48 | 0 | if (i >= aBufferLength-2) { |
49 | 0 | ok = false; |
50 | 0 | } |
51 | 0 | aBuffer[i] = '0'; |
52 | 0 | } |
53 | 0 | aBuffer[i] = '\0'; |
54 | 0 | } |
55 | 0 | return ok; |
56 | 0 | } |