Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Unified Diff: core/src/fxcrt/fx_basic_gcc.cpp

Issue 1409223002: fxcrt convergence - XFA side. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: GN. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/src/fxcrt/fx_arabic.cpp ('k') | core/src/fxcrt/fx_system_unittest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fxcrt/fx_basic_gcc.cpp
diff --git a/core/src/fxcrt/fx_basic_gcc.cpp b/core/src/fxcrt/fx_basic_gcc.cpp
index bf3d61524ec832d824b899bf16310660d702b464..6f17482156be7436f0e53e55243b2e1a63548202 100644
--- a/core/src/fxcrt/fx_basic_gcc.cpp
+++ b/core/src/fxcrt/fx_basic_gcc.cpp
@@ -32,30 +32,41 @@ T FXSYS_StrToInt(STR_T str) {
}
return neg ? -num : num;
}
-template <typename T, typename STR_T>
+
+template <typename T, typename UT, typename STR_T>
STR_T FXSYS_IntToStr(T value, STR_T string, int radix) {
- int i = 0;
- if (value < 0) {
- string[i++] = '-';
- value = -value;
- } else if (value == 0) {
+ if (radix < 2 || radix > 16) {
+ string[0] = 0;
+ return string;
+ }
+ if (value == 0) {
string[0] = '0';
string[1] = 0;
return string;
}
+ int i = 0;
+ UT uvalue;
+ if (value < 0) {
+ string[i++] = '-';
+ // Standard trick to avoid undefined behaviour when negating INT_MIN.
+ uvalue = static_cast<UT>(-(value + 1)) + 1;
+ } else {
+ uvalue = value;
+ }
int digits = 1;
- T order = value / 10;
+ T order = uvalue / radix;
while (order > 0) {
digits++;
- order = order / 10;
+ order = order / radix;
}
for (int d = digits - 1; d > -1; d--) {
- string[d + i] = "0123456789abcdef"[value % 10];
- value /= 10;
+ string[d + i] = "0123456789abcdef"[uvalue % radix];
+ uvalue /= radix;
}
string[digits + i] = 0;
return string;
}
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -72,10 +83,7 @@ int64_t FXSYS_wtoi64(const FX_WCHAR* str) {
return FXSYS_StrToInt<int64_t, const FX_WCHAR*>(str);
}
const FX_CHAR* FXSYS_i64toa(int64_t value, FX_CHAR* str, int radix) {
- return FXSYS_IntToStr<int64_t, FX_CHAR*>(value, str, radix);
-}
-const FX_WCHAR* FXSYS_i64tow(int64_t value, FX_WCHAR* str, int radix) {
- return FXSYS_IntToStr<int64_t, FX_WCHAR*>(value, str, radix);
+ return FXSYS_IntToStr<int64_t, uint64_t, FX_CHAR*>(value, str, radix);
}
#ifdef __cplusplus
}
@@ -182,7 +190,7 @@ int FXSYS_wcsicmp(const FX_WCHAR* dst, const FX_WCHAR* src) {
return (f - l);
}
char* FXSYS_itoa(int value, char* string, int radix) {
- return FXSYS_IntToStr<int32_t, FX_CHAR*>(value, string, radix);
+ return FXSYS_IntToStr<int32_t, uint32_t, FX_CHAR*>(value, string, radix);
}
#ifdef __cplusplus
}
« no previous file with comments | « core/src/fxcrt/fx_arabic.cpp ('k') | core/src/fxcrt/fx_system_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698