Skip to content

Commit

Permalink
type cast problems in scan_for_intN(),scan_for_uintN()
Browse files Browse the repository at this point in the history
  • Loading branch information
jfzheng committed Jan 25, 2016
1 parent 479c98f commit 97e3e69
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions libsim/sim_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,10 @@ static int scan_for_intN(const char *_str, int Nbit, int64_t *ret_, const char *
Nbit == 32 ? INT32_MAX : (
Nbit == 16 ? INT16_MAX : (
Nbit == 8 ? INT8_MAX : 0))));
max += (b_neg ? 1 : 0);

b_err = scan_for_uint64_pre(_str, max, &ret, &end);

if (ret_) { *ret_ = b_neg ? -ret : ret; }
if (ret_) { *ret_ = b_neg ? -(int64_t)ret : ret; }
if (end_) { *end_ = end; }

return b_err;
Expand All @@ -467,15 +466,15 @@ int scan_for_uint32(const char *_str, uint32_t *ret_, const char **end_)
{
uint64_t ret;
int b_err = scan_for_uintN(_str, 32, &ret, end_);
if (ret_) { *ret_ = ret; }
if (ret_) { *ret_ = (uint32_t)ret; }

return b_err;
}
int scan_for_uint16(const char *_str, uint16_t *ret_, const char **end_)
{
uint64_t ret;
int b_err = scan_for_uintN(_str, 16, &ret, end_);
if (ret_) { *ret_ = ret; }
if (ret_) { *ret_ = (uint16_t)ret; }

return b_err;
}
Expand All @@ -491,15 +490,15 @@ int scan_for_int32(const char *_str, int32_t *ret_, const char **end_)
{
int64_t ret;
int b_err = scan_for_intN(_str, 32, &ret, end_);
if (ret_) { *ret_ = ret; }
if (ret_) { *ret_ = (int32_t)ret; }

return b_err;
}
int scan_for_int16(const char *_str, int16_t *ret_, const char **end_)
{
int64_t ret;
int b_err = scan_for_intN(_str, 16, &ret, end_);
if (ret_) { *ret_ = ret; }
if (ret_) { *ret_ = (int16_t)ret; }

return b_err;
}
Expand Down Expand Up @@ -562,7 +561,7 @@ int scan_for_float(const char *_str, float *ret_, const char **end_)
return b_err;
}

int str_2_uint(const char *_str, unsigned int *ret_)
unsigned int str_2_uint(const char *_str, unsigned int *ret_)
{
uint64_t ret;
const char *end;
Expand All @@ -572,7 +571,7 @@ int str_2_uint(const char *_str, unsigned int *ret_)
xerr("str_2_uint(%s) not nul ending\n", _str);
b_err |= SCAN_ERR_NNULEND;
}
if (ret_) { *ret_ = ret; }
if (ret_) { *ret_ = (unsigned int)ret; }

return b_err;
}
Expand All @@ -586,7 +585,7 @@ int str_2_int(const char *_str, int *ret_)
xerr("str_2_int(%s) not nul ending\n", _str);
b_err |= SCAN_ERR_NNULEND;
}
if (ret_) { *ret_ = ret; }
if (ret_) { *ret_ = (int)ret; }

return b_err;
}
Expand Down
4 changes: 2 additions & 2 deletions libsim/sim_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ typedef struct str_iterator {
int sublen;
}str_iter_t;

str_iter_t str_iter_init(char *str, const int len);
str_iter_t str_iter_init(char *str, int len);

char *str_iter_1st_field(str_iter_t *iter,
const char* prejumpset,
Expand Down Expand Up @@ -235,7 +235,7 @@ int scan_for_int64(const char *_str, int64_t *ret_, const char **end_);
int scan_for_int32(const char *_str, int32_t *ret_, const char **end_);
int scan_for_int16(const char *_str, int16_t *ret_, const char **end_);
int scan_for_float(const char *_str, float *ret_, const char **end_);
int str_2_uint(const char *_str, unsigned int *ret_);
unsigned int str_2_uint(const char *_str, unsigned int *ret_);
int str_2_int(const char *_str, int *ret_);


Expand Down

0 comments on commit 97e3e69

Please sign in to comment.