Skip to content

Commit

Permalink
small enhancements
Browse files Browse the repository at this point in the history
- have wstr conversions to longs also return EINVAL on failed conversion;
- adapt error propagation to this change;
- adjust error reporting to correctly log failed conversion.
  • Loading branch information
bpintea committed Jun 27, 2018
1 parent 3026383 commit f194e5c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions driver/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ static SQLRETURN process_config(esodbc_dbc_st *dbc, config_attrs_st *attrs)
* request timeout for liburl: negative reset to 0
*/
if (! wstr2llong(&attrs->timeout, &timeout)) {
ERRH(dbc, "failed to convert '" LWPDL "' to long.",
ERRH(dbc, "failed to convert '" LWPDL "' to long long.",
LWSTR(&attrs->timeout));
goto err;
}
Expand All @@ -1018,7 +1018,7 @@ static SQLRETURN process_config(esodbc_dbc_st *dbc, config_attrs_st *attrs)
* set max body size
*/
if (! wstr2llong(&attrs->max_body_size, &max_body_size)) {
ERRH(dbc, "failed to convert '" LWPDL "' to long.",
ERRH(dbc, "failed to convert '" LWPDL "' to long long.",
LWSTR(&attrs->max_body_size));
goto err;
}
Expand All @@ -1035,7 +1035,7 @@ static SQLRETURN process_config(esodbc_dbc_st *dbc, config_attrs_st *attrs)
* set max fetch size
*/
if (! wstr2llong(&attrs->max_fetch_size, &max_fetch_size)) {
ERRH(dbc, "failed to convert '" LWPDL "' to long.",
ERRH(dbc, "failed to convert '" LWPDL "' to long long.",
LWSTR(&attrs->max_fetch_size));
goto err;
}
Expand Down
13 changes: 8 additions & 5 deletions driver/queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,8 @@ static SQLRETURN copy_string(esodbc_rec_st *arec, esodbc_rec_st *irec,
errno = 0;
if (! wstr2llong(&wval, &ll)) { /* string is 0-term -> wcstoll? */
ERRH(stmt, "can't convert `" LWPD "` to long long.", wstr);
RET_HDIAGS(stmt, errno ? SQL_STATE_22003 : SQL_STATE_22018);
RET_HDIAGS(stmt, errno == ERANGE ? SQL_STATE_22003 :
SQL_STATE_22018);
}
DBGH(stmt, "string `" LWPD "` converted to LL=%lld.", wstr, ll);
/* delegate to existing functionality */
Expand All @@ -1876,7 +1877,8 @@ static SQLRETURN copy_string(esodbc_rec_st *arec, esodbc_rec_st *irec,
if (! wstr2ullong(&wval, &ull)) { /* string is 0-term: wcstoull? */
ERRH(stmt, "can't convert `" LWPD "` to unsigned long long.",
wstr);
RET_HDIAGS(stmt, errno ? SQL_STATE_22003 : SQL_STATE_22018);
RET_HDIAGS(stmt, errno == ERANGE ? SQL_STATE_22003 :
SQL_STATE_22018);
}
DBGH(stmt, "string `" LWPD "` converted to ULL=%llu.", wstr, ull);
if (ull <= LLONG_MAX) {
Expand All @@ -1894,7 +1896,7 @@ static SQLRETURN copy_string(esodbc_rec_st *arec, esodbc_rec_st *irec,
*(SQLUBIGINT *)data_ptr = (SQLUBIGINT)ull;
write_out_octets(octet_len_ptr, sizeof(SQLUBIGINT), irec);
DBGH(stmt, "converted string `" LWPD "` to "
"unsigned long long %llu.", wstr, ull);
"unsigned long long %llu.", wstr, ull);
} else {
REJECT_AS_OOR(stmt, ull, /*fixed?*/TRUE, "non-ULL");
}
Expand All @@ -1914,14 +1916,15 @@ static SQLRETURN copy_string(esodbc_rec_st *arec, esodbc_rec_st *irec,
/* if empty string, non-numeric or under/over-flow, bail out */
if ((! wval.cnt) || (wval.str + wval.cnt != endp) || errno) {
ERRH(stmt, "can't convert `" LWPD "` to double.", wstr);
RET_HDIAGS(stmt, errno ? SQL_STATE_22003 : SQL_STATE_22018);
RET_HDIAGS(stmt, errno == ERANGE ? SQL_STATE_22003 :
SQL_STATE_22018);
}
/* delegate to existing functionality */
return copy_double(arec, irec, pos, dbl);


default:
BUGH(stmt, "unexpected unhanlded data type: %d.",
BUGH(stmt, "unexpected unhandled data type: %d.",
get_c_target_type(arec, irec));
return SQL_ERROR;
}
Expand Down
3 changes: 3 additions & 0 deletions driver/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ BOOL wstr2ullong(wstr_st *val, unsigned long long *out)
int i = 0;

if (val->cnt < 1) {
errno = EINVAL;
return FALSE;
} else if (val->str[0] == L'+') {
i ++;
Expand All @@ -40,6 +41,7 @@ BOOL wstr2ullong(wstr_st *val, unsigned long long *out)
for (res = 0; i < val->cnt; i ++) {
/* is it a number? */
if (val->str[i] < L'0' || L'9' < val->str[i]) {
errno = EINVAL;
return FALSE;
} else {
digit = val->str[i] - L'0';
Expand Down Expand Up @@ -76,6 +78,7 @@ BOOL wstr2llong(wstr_st *val, long long *out)
BOOL negative;

if (val->cnt < 1) {
errno = EINVAL;
return FALSE;
} else {
switch (val->str[0]) {
Expand Down

0 comments on commit f194e5c

Please sign in to comment.