mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
s3: Slightly simplify logic in conv_str_size
This commit is contained in:
parent
ea0f9378a0
commit
d77a1fb272
@ -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 (*end == '\0') {
|
||||
return 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;
|
||||
}
|
||||
lval_orig = lval;
|
||||
|
||||
/* 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 (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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user