mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
s3-lib: Rely on uint64_t in conv_str_size()
Autobuild-User: Andrew Bartlett <abartlet@samba.org> Autobuild-Date: Sat Apr 30 05:58:35 CEST 2011 on sn-devel-104
This commit is contained in:
parent
e1eae82285
commit
1018dd1826
@ -1007,7 +1007,7 @@ char *ipstr_list_make(char **ipstr_list,
|
|||||||
int ipstr_list_parse(const char *ipstr_list, struct ip_service **ip_list);
|
int ipstr_list_parse(const char *ipstr_list, struct ip_service **ip_list);
|
||||||
void ipstr_list_free(char* ipstr_list);
|
void ipstr_list_free(char* ipstr_list);
|
||||||
uint64_t STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr);
|
uint64_t STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr);
|
||||||
SMB_OFF_T conv_str_size(const char * str);
|
uint64_t conv_str_size(const char * str);
|
||||||
bool add_string_to_array(TALLOC_CTX *mem_ctx,
|
bool add_string_to_array(TALLOC_CTX *mem_ctx,
|
||||||
const char *str, const char ***strings,
|
const char *str, const char ***strings,
|
||||||
int *num);
|
int *num);
|
||||||
|
@ -1206,25 +1206,17 @@ uint64_t STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr)
|
|||||||
*
|
*
|
||||||
* Returns 0 if the string can't be converted.
|
* Returns 0 if the string can't be converted.
|
||||||
*/
|
*/
|
||||||
SMB_OFF_T conv_str_size(const char * str)
|
uint64_t conv_str_size(const char * str)
|
||||||
{
|
{
|
||||||
SMB_OFF_T lval_orig;
|
uint64_t lval_orig;
|
||||||
SMB_OFF_T lval;
|
uint64_t lval;
|
||||||
char * end;
|
char * end;
|
||||||
|
|
||||||
if (str == NULL || *str == '\0') {
|
if (str == NULL || *str == '\0') {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_STRTOULL
|
lval = strtoull(str, &end, 10 /* base */);
|
||||||
if (sizeof(SMB_OFF_T) == 8) {
|
|
||||||
lval = strtoull(str, &end, 10 /* base */);
|
|
||||||
} else {
|
|
||||||
lval = strtoul(str, &end, 10 /* base */);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
lval = strtoul(str, &end, 10 /* base */);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (end == NULL || end == str) {
|
if (end == NULL || end == str) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -1237,32 +1229,23 @@ SMB_OFF_T conv_str_size(const char * str)
|
|||||||
lval_orig = lval;
|
lval_orig = lval;
|
||||||
|
|
||||||
if (strwicmp(end, "K") == 0) {
|
if (strwicmp(end, "K") == 0) {
|
||||||
lval *= (SMB_OFF_T)1024;
|
lval *= 1024ULL;
|
||||||
} else if (strwicmp(end, "M") == 0) {
|
} else if (strwicmp(end, "M") == 0) {
|
||||||
lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024);
|
lval *= (1024ULL * 1024ULL);
|
||||||
} else if (strwicmp(end, "G") == 0) {
|
} else if (strwicmp(end, "G") == 0) {
|
||||||
lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
|
lval *= (1024ULL * 1024ULL *
|
||||||
(SMB_OFF_T)1024);
|
1024ULL);
|
||||||
} else if (strwicmp(end, "T") == 0) {
|
} else if (strwicmp(end, "T") == 0) {
|
||||||
lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
|
lval *= (1024ULL * 1024ULL *
|
||||||
(SMB_OFF_T)1024 * (SMB_OFF_T)1024);
|
1024ULL * 1024ULL);
|
||||||
} else if (strwicmp(end, "P") == 0) {
|
} else if (strwicmp(end, "P") == 0) {
|
||||||
lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
|
lval *= (1024ULL * 1024ULL *
|
||||||
(SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
|
1024ULL * 1024ULL *
|
||||||
(SMB_OFF_T)1024);
|
1024ULL);
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
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;
|
return lval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user