aboutsummaryrefslogtreecommitdiff
path: root/libbb/xfuncs.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-03-28 17:12:56 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-03-28 17:12:56 +0200
commite4defe826be49b8ef19912ba4cb291bfe9166e0f (patch)
treec22925d5ec279ce799525879edc9f21961b4764a /libbb/xfuncs.c
parent123fdda0a4a838e61c6a7d15c69d3b438136aee0 (diff)
downloadbusybox-w32-e4defe826be49b8ef19912ba4cb291bfe9166e0f.tar.gz
busybox-w32-e4defe826be49b8ef19912ba4cb291bfe9166e0f.tar.bz2
busybox-w32-e4defe826be49b8ef19912ba4cb291bfe9166e0f.zip
libbb: use BUILD_BUG_ON in utoa_to_buf()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r--libbb/xfuncs.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 43ae98065..e8c027f17 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -59,24 +59,23 @@ char* FAST_FUNC strncpy_IFNAMSIZ(char *dst, const char *src)
59 * A truncated result contains the first few digits of the result ala strncpy. 59 * A truncated result contains the first few digits of the result ala strncpy.
60 * Returns a pointer past last generated digit, does _not_ store NUL. 60 * Returns a pointer past last generated digit, does _not_ store NUL.
61 */ 61 */
62void BUG_sizeof(void);
63char* FAST_FUNC utoa_to_buf(unsigned n, char *buf, unsigned buflen) 62char* FAST_FUNC utoa_to_buf(unsigned n, char *buf, unsigned buflen)
64{ 63{
65 unsigned i, out, res; 64 unsigned i, out, res;
66 65
67 if (buflen) { 66 if (buflen) {
68 out = 0; 67 out = 0;
68
69 BUILD_BUG_ON(sizeof(n) != 4 && sizeof(n) != 8);
69 if (sizeof(n) == 4) 70 if (sizeof(n) == 4)
70 // 2^32-1 = 4294967295 71 // 2^32-1 = 4294967295
71 i = 1000000000; 72 i = 1000000000;
72#if UINT_MAX > 4294967295 /* prevents warning about "const too large" */ 73#if UINT_MAX > 0xffffffff /* prevents warning about "const too large" */
73 else 74 else
74 if (sizeof(n) == 8) 75 if (sizeof(n) == 8)
75 // 2^64-1 = 18446744073709551615 76 // 2^64-1 = 18446744073709551615
76 i = 10000000000000000000; 77 i = 10000000000000000000;
77#endif 78#endif
78 else
79 BUG_sizeof();
80 for (; i; i /= 10) { 79 for (; i; i /= 10) {
81 res = n / i; 80 res = n / i;
82 n = n % i; 81 n = n % i;