aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorted.mielczarek@gmail.com <ted.mielczarek@gmail.com@4c0a9323-5329-0410-9bdc-e9ce6186880e>2012-09-17 14:01:19 +0000
committerted.mielczarek@gmail.com <ted.mielczarek@gmail.com@4c0a9323-5329-0410-9bdc-e9ce6186880e>2012-09-17 14:01:19 +0000
commita61c7e6927a25e7ce00854b1872561000a6ce8b5 (patch)
tree63b3f65af93e79a798192a3c867a0c258d062a5b /src/common
parentAllow setting a new MinidumpDescriptor on ExceptionHandler, also expose direc... (diff)
downloadbreakpad-a61c7e6927a25e7ce00854b1872561000a6ce8b5.tar.xz
Make my_str_len/my_itos take uintmax_t
R=digit at https://breakpad.appspot.com/452004/ git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1038 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/common')
-rw-r--r--src/common/linux/linux_libc_support.cc15
-rw-r--r--src/common/linux/linux_libc_support.h13
-rw-r--r--src/common/linux/linux_libc_support_unittest.cc40
3 files changed, 36 insertions, 32 deletions
diff --git a/src/common/linux/linux_libc_support.cc b/src/common/linux/linux_libc_support.cc
index 39e2aa1e..845729c9 100644
--- a/src/common/linux/linux_libc_support.cc
+++ b/src/common/linux/linux_libc_support.cc
@@ -95,9 +95,8 @@ bool my_strtoui(int* result, const char* s) {
return true;
}
-// Return the length of the given, non-negative integer when expressed in base
-// 10.
-unsigned my_int_len(intmax_t i) {
+// Return the length of the given unsigned integer when expressed in base 10.
+unsigned my_uint_len(uintmax_t i) {
if (!i)
return 1;
@@ -110,13 +109,13 @@ unsigned my_int_len(intmax_t i) {
return len;
}
-// Convert a non-negative integer to a string
+// Convert an unsigned integer to a string
// output: (output) the resulting string is written here. This buffer must be
-// large enough to hold the resulting string. Call |my_int_len| to get the
+// large enough to hold the resulting string. Call |my_uint_len| to get the
// required length.
-// i: the non-negative integer to serialise.
-// i_len: the length of the integer in base 10 (see |my_int_len|).
-void my_itos(char* output, intmax_t i, unsigned i_len) {
+// i: the unsigned integer to serialise.
+// i_len: the length of the integer in base 10 (see |my_uint_len|).
+void my_uitos(char* output, uintmax_t i, unsigned i_len) {
for (unsigned index = i_len; index; --index, i /= 10)
output[index - 1] = '0' + (i % 10);
}
diff --git a/src/common/linux/linux_libc_support.h b/src/common/linux/linux_libc_support.h
index b2f47af8..011048f8 100644
--- a/src/common/linux/linux_libc_support.h
+++ b/src/common/linux/linux_libc_support.h
@@ -52,17 +52,16 @@ extern int my_strncmp(const char* a, const char* b, size_t len);
// Return true iff successful.
extern bool my_strtoui(int* result, const char* s);
-// Return the length of the given, non-negative integer when expressed in base
-// 10.
-extern unsigned my_int_len(intmax_t i);
+// Return the length of the given unsigned integer when expressed in base 10.
+extern unsigned my_uint_len(uintmax_t i);
-// Convert a non-negative integer to a string
+// Convert an unsigned integer to a string
// output: (output) the resulting string is written here. This buffer must be
// large enough to hold the resulting string. Call |my_int_len| to get the
// required length.
-// i: the non-negative integer to serialise.
-// i_len: the length of the integer in base 10 (see |my_int_len|).
-extern void my_itos(char* output, intmax_t i, unsigned i_len);
+// i: the unsigned integer to serialise.
+// i_len: the length of the integer in base 10 (see |my_uint_len|).
+extern void my_uitos(char* output, uintmax_t i, unsigned i_len);
extern const char* my_strchr(const char* haystack, char needle);
diff --git a/src/common/linux/linux_libc_support_unittest.cc b/src/common/linux/linux_libc_support_unittest.cc
index 7f974af8..2a9694ce 100644
--- a/src/common/linux/linux_libc_support_unittest.cc
+++ b/src/common/linux/linux_libc_support_unittest.cc
@@ -89,35 +89,41 @@ TEST(LinuxLibcSupportTest, strtoui) {
ASSERT_EQ(result, 123);
}
-TEST(LinuxLibcSupportTest, int_len) {
- ASSERT_EQ(my_int_len(0), 1);
- ASSERT_EQ(my_int_len(2), 1);
- ASSERT_EQ(my_int_len(5), 1);
- ASSERT_EQ(my_int_len(9), 1);
- ASSERT_EQ(my_int_len(10), 2);
- ASSERT_EQ(my_int_len(99), 2);
- ASSERT_EQ(my_int_len(100), 3);
- ASSERT_EQ(my_int_len(101), 3);
- ASSERT_EQ(my_int_len(1000), 4);
+TEST(LinuxLibcSupportTest, uint_len) {
+ ASSERT_EQ(my_uint_len(0), 1);
+ ASSERT_EQ(my_uint_len(2), 1);
+ ASSERT_EQ(my_uint_len(5), 1);
+ ASSERT_EQ(my_uint_len(9), 1);
+ ASSERT_EQ(my_uint_len(10), 2);
+ ASSERT_EQ(my_uint_len(99), 2);
+ ASSERT_EQ(my_uint_len(100), 3);
+ ASSERT_EQ(my_uint_len(101), 3);
+ ASSERT_EQ(my_uint_len(1000), 4);
+ // 0xFFFFFFFFFFFFFFFF
+ ASSERT_EQ(my_uint_len(18446744073709551615LLU), 20);
}
-TEST(LinuxLibcSupportTest, itos) {
- char buf[10];
+TEST(LinuxLibcSupportTest, uitos) {
+ char buf[32];
- my_itos(buf, 0, 1);
+ my_uitos(buf, 0, 1);
ASSERT_EQ(0, memcmp(buf, "0", 1));
- my_itos(buf, 1, 1);
+ my_uitos(buf, 1, 1);
ASSERT_EQ(0, memcmp(buf, "1", 1));
- my_itos(buf, 10, 2);
+ my_uitos(buf, 10, 2);
ASSERT_EQ(0, memcmp(buf, "10", 2));
- my_itos(buf, 63, 2);
+ my_uitos(buf, 63, 2);
ASSERT_EQ(0, memcmp(buf, "63", 2));
- my_itos(buf, 101, 3);
+ my_uitos(buf, 101, 3);
ASSERT_EQ(0, memcmp(buf, "101", 2));
+
+ // 0xFFFFFFFFFFFFFFFF
+ my_uitos(buf, 18446744073709551615LLU, 20);
+ ASSERT_EQ(0, memcmp(buf, "18446744073709551615", 20));
}
TEST(LinuxLibcSupportTest, strchr) {