From d77a1fb272d06e9fa4f4b1cbe9b151625334ca9f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 28 Mar 2010 13:16:58 +0200 Subject: s3: Slightly simplify logic in conv_str_size --- source3/lib/util_str.c | 62 +++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 29 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 22167d7ff2..3247682907 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -2003,6 +2003,7 @@ uint64_t STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr) */ SMB_OFF_T conv_str_size(const char * str) { + SMB_OFF_T lval_orig; SMB_OFF_T lval; char * end; @@ -2024,35 +2025,38 @@ SMB_OFF_T conv_str_size(const char * str) return 0; } - if (*end) { - SMB_OFF_T lval_orig = lval; - - if (strwicmp(end, "K") == 0) { - lval *= (SMB_OFF_T)1024; - } else if (strwicmp(end, "M") == 0) { - lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024); - } else if (strwicmp(end, "G") == 0) { - lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * - (SMB_OFF_T)1024); - } else if (strwicmp(end, "T") == 0) { - lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * - (SMB_OFF_T)1024 * (SMB_OFF_T)1024); - } else if (strwicmp(end, "P") == 0) { - lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * - (SMB_OFF_T)1024 * (SMB_OFF_T)1024 * - (SMB_OFF_T)1024); - } else { - return 0; - } - - /* Primitive attempt to detect wrapping on platforms with - * 4-byte SMB_OFF_T. It's better to let the caller handle - * a failure than some random number. - */ - if (lval_orig <= lval) { - return 0; - } - } + if (*end == '\0') { + return lval; + } + + lval_orig = lval; + + if (strwicmp(end, "K") == 0) { + lval *= (SMB_OFF_T)1024; + } else if (strwicmp(end, "M") == 0) { + lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024); + } else if (strwicmp(end, "G") == 0) { + lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * + (SMB_OFF_T)1024); + } else if (strwicmp(end, "T") == 0) { + lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * + (SMB_OFF_T)1024 * (SMB_OFF_T)1024); + } else if (strwicmp(end, "P") == 0) { + lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * + (SMB_OFF_T)1024 * (SMB_OFF_T)1024 * + (SMB_OFF_T)1024); + } else { + return 0; + } + + /* + * Primitive attempt to detect wrapping on platforms with + * 4-byte SMB_OFF_T. It's better to let the caller handle a + * failure than some random number. + */ + if (lval_orig <= lval) { + return 0; + } return lval; } -- cgit