diff options
author | Volker Lendecke <vl@samba.org> | 2010-03-28 13:16:58 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2010-03-28 15:25:15 +0200 |
commit | d77a1fb272d06e9fa4f4b1cbe9b151625334ca9f (patch) | |
tree | 0d6f9bc96b5adc52c9c7e33ecea8e3da2ce412be | |
parent | ea0f9378a02ed3b64ab3b4f71862bfcb449d2b42 (diff) | |
download | samba-d77a1fb272d06e9fa4f4b1cbe9b151625334ca9f.tar.gz samba-d77a1fb272d06e9fa4f4b1cbe9b151625334ca9f.tar.bz2 samba-d77a1fb272d06e9fa4f4b1cbe9b151625334ca9f.zip |
s3: Slightly simplify logic in conv_str_size
-rw-r--r-- | source3/lib/util_str.c | 62 |
1 files changed, 33 insertions, 29 deletions
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; } |