Skip to content

Commit f194e5c

Browse files
committed
small enhancements
- 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.
1 parent 3026383 commit f194e5c

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

driver/connect.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ static SQLRETURN process_config(esodbc_dbc_st *dbc, config_attrs_st *attrs)
10031003
* request timeout for liburl: negative reset to 0
10041004
*/
10051005
if (! wstr2llong(&attrs->timeout, &timeout)) {
1006-
ERRH(dbc, "failed to convert '" LWPDL "' to long.",
1006+
ERRH(dbc, "failed to convert '" LWPDL "' to long long.",
10071007
LWSTR(&attrs->timeout));
10081008
goto err;
10091009
}
@@ -1018,7 +1018,7 @@ static SQLRETURN process_config(esodbc_dbc_st *dbc, config_attrs_st *attrs)
10181018
* set max body size
10191019
*/
10201020
if (! wstr2llong(&attrs->max_body_size, &max_body_size)) {
1021-
ERRH(dbc, "failed to convert '" LWPDL "' to long.",
1021+
ERRH(dbc, "failed to convert '" LWPDL "' to long long.",
10221022
LWSTR(&attrs->max_body_size));
10231023
goto err;
10241024
}
@@ -1035,7 +1035,7 @@ static SQLRETURN process_config(esodbc_dbc_st *dbc, config_attrs_st *attrs)
10351035
* set max fetch size
10361036
*/
10371037
if (! wstr2llong(&attrs->max_fetch_size, &max_fetch_size)) {
1038-
ERRH(dbc, "failed to convert '" LWPDL "' to long.",
1038+
ERRH(dbc, "failed to convert '" LWPDL "' to long long.",
10391039
LWSTR(&attrs->max_fetch_size));
10401040
goto err;
10411041
}

driver/queries.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,8 @@ static SQLRETURN copy_string(esodbc_rec_st *arec, esodbc_rec_st *irec,
18581858
errno = 0;
18591859
if (! wstr2llong(&wval, &ll)) { /* string is 0-term -> wcstoll? */
18601860
ERRH(stmt, "can't convert `" LWPD "` to long long.", wstr);
1861-
RET_HDIAGS(stmt, errno ? SQL_STATE_22003 : SQL_STATE_22018);
1861+
RET_HDIAGS(stmt, errno == ERANGE ? SQL_STATE_22003 :
1862+
SQL_STATE_22018);
18621863
}
18631864
DBGH(stmt, "string `" LWPD "` converted to LL=%lld.", wstr, ll);
18641865
/* delegate to existing functionality */
@@ -1876,7 +1877,8 @@ static SQLRETURN copy_string(esodbc_rec_st *arec, esodbc_rec_st *irec,
18761877
if (! wstr2ullong(&wval, &ull)) { /* string is 0-term: wcstoull? */
18771878
ERRH(stmt, "can't convert `" LWPD "` to unsigned long long.",
18781879
wstr);
1879-
RET_HDIAGS(stmt, errno ? SQL_STATE_22003 : SQL_STATE_22018);
1880+
RET_HDIAGS(stmt, errno == ERANGE ? SQL_STATE_22003 :
1881+
SQL_STATE_22018);
18801882
}
18811883
DBGH(stmt, "string `" LWPD "` converted to ULL=%llu.", wstr, ull);
18821884
if (ull <= LLONG_MAX) {
@@ -1894,7 +1896,7 @@ static SQLRETURN copy_string(esodbc_rec_st *arec, esodbc_rec_st *irec,
18941896
*(SQLUBIGINT *)data_ptr = (SQLUBIGINT)ull;
18951897
write_out_octets(octet_len_ptr, sizeof(SQLUBIGINT), irec);
18961898
DBGH(stmt, "converted string `" LWPD "` to "
1897-
"unsigned long long %llu.", wstr, ull);
1899+
"unsigned long long %llu.", wstr, ull);
18981900
} else {
18991901
REJECT_AS_OOR(stmt, ull, /*fixed?*/TRUE, "non-ULL");
19001902
}
@@ -1914,14 +1916,15 @@ static SQLRETURN copy_string(esodbc_rec_st *arec, esodbc_rec_st *irec,
19141916
/* if empty string, non-numeric or under/over-flow, bail out */
19151917
if ((! wval.cnt) || (wval.str + wval.cnt != endp) || errno) {
19161918
ERRH(stmt, "can't convert `" LWPD "` to double.", wstr);
1917-
RET_HDIAGS(stmt, errno ? SQL_STATE_22003 : SQL_STATE_22018);
1919+
RET_HDIAGS(stmt, errno == ERANGE ? SQL_STATE_22003 :
1920+
SQL_STATE_22018);
19181921
}
19191922
/* delegate to existing functionality */
19201923
return copy_double(arec, irec, pos, dbl);
19211924

19221925

19231926
default:
1924-
BUGH(stmt, "unexpected unhanlded data type: %d.",
1927+
BUGH(stmt, "unexpected unhandled data type: %d.",
19251928
get_c_target_type(arec, irec));
19261929
return SQL_ERROR;
19271930
}

driver/util.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ BOOL wstr2ullong(wstr_st *val, unsigned long long *out)
3232
int i = 0;
3333

3434
if (val->cnt < 1) {
35+
errno = EINVAL;
3536
return FALSE;
3637
} else if (val->str[0] == L'+') {
3738
i ++;
@@ -40,6 +41,7 @@ BOOL wstr2ullong(wstr_st *val, unsigned long long *out)
4041
for (res = 0; i < val->cnt; i ++) {
4142
/* is it a number? */
4243
if (val->str[i] < L'0' || L'9' < val->str[i]) {
44+
errno = EINVAL;
4345
return FALSE;
4446
} else {
4547
digit = val->str[i] - L'0';
@@ -76,6 +78,7 @@ BOOL wstr2llong(wstr_st *val, long long *out)
7678
BOOL negative;
7779

7880
if (val->cnt < 1) {
81+
errno = EINVAL;
7982
return FALSE;
8083
} else {
8184
switch (val->str[0]) {

0 commit comments

Comments
 (0)