summaryrefslogtreecommitdiff
path: root/source3/lib/util_str.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib/util_str.c')
-rw-r--r--source3/lib/util_str.c62
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;
}