Skip to content

Commit 2d07ebe

Browse files
committed
Fix debug printing of SQL(U)LEN variables (#233)
* Fix debug printing of SQL(U)LEN variables This fixes the debug printing of SQL(U)LEN variable types. This type is defined as a long on WIN32, but a __int64 on WIN64. The "%llu"/"%lld" specifier had be used from the start, before the need for an x86 driver was considered and stayed like that mostly since. The values logged by an x86 drivers contains the actual values of the variable, but one needs to convert to hexa, remove the upper 4 byte and convert back, which is cumbersome. The values are now promoted to a (u)int64_t in the logging statements, so printf will always log the correct value. This change also updates some other few incorrect specifiers. * address review comments - fix cast for '%llu' specifier to uint64_t (cherry picked from commit bd81338)
1 parent 88c225d commit 2d07ebe

File tree

5 files changed

+99
-86
lines changed

5 files changed

+99
-86
lines changed

driver/connect.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,7 +2411,7 @@ static void set_display_size(esodbc_estype_st *es_type)
24112411
}
24122412

24132413
DBG("data type: %hd, display size: %lld", es_type->data_type,
2414-
es_type->display_size);
2414+
(int64_t)es_type->display_size);
24152415
}
24162416

24172417
static BOOL bind_types_cols(esodbc_stmt_st *stmt, estype_row_st *type_row)
@@ -3248,14 +3248,14 @@ SQLRETURN EsSQLSetConnectAttrW(
32483248

32493249
case SQL_ATTR_ASYNC_ENABLE:
32503250
ERRH(dbc, "no support for async API (setting param: %llu)",
3251-
(SQLULEN)(uintptr_t)Value);
3251+
(uint64_t)Value);
32523252
if ((SQLULEN)(uintptr_t)Value == SQL_ASYNC_ENABLE_ON) {
32533253
RET_HDIAGS(dbc, SQL_STATE_HYC00);
32543254
}
32553255
break;
32563256
case SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE:
32573257
ERRH(dbc, "no support for async API (setting param: %llu)",
3258-
(SQLULEN)(uintptr_t)Value);
3258+
(uint64_t)Value);
32593259
if ((SQLULEN)(uintptr_t)Value == SQL_ASYNC_DBC_ENABLE_ON) {
32603260
RET_HDIAGS(dbc, SQL_STATE_HY114);
32613261
}
@@ -3354,8 +3354,8 @@ SQLRETURN EsSQLSetConnectAttrW(
33543354

33553355
case SQL_ATTR_MAX_ROWS: /* stmt attr -- 2.x app */
33563356
WARNH(dbc, "applying a statement as connection attribute (2.x?)");
3357-
DBGH(dbc, "setting max rows: %llu.", (SQLULEN)Value);
3358-
if ((SQLULEN)Value != 0) {
3357+
DBGH(dbc, "setting max rows: %llu.", (uint64_t)Value);
3358+
if (Value) {
33593359
WARNH(dbc, "requested max_rows substituted with 0.");
33603360
RET_HDIAGS(dbc, SQL_STATE_01S02);
33613361
}
@@ -3413,7 +3413,7 @@ SQLRETURN EsSQLGetConnectAttrW(
34133413
*(SQLULEN *)ValuePtr = dbc->metadata_id;
34143414
break;
34153415
case SQL_ATTR_ASYNC_ENABLE:
3416-
DBGH(dbc, "getting async mode: %llu", SQL_ASYNC_ENABLE_OFF);
3416+
DBGH(dbc, "getting async mode: %lu", SQL_ASYNC_ENABLE_OFF);
34173417
*(SQLULEN *)ValuePtr = SQL_ASYNC_ENABLE_OFF;
34183418
break;
34193419

driver/convert.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ inline void *deferred_address(SQLSMALLINT field_id, size_t pos,
447447
#undef ROW_OFFSETS
448448

449449
DBGH(desc->hdr.stmt, "rec@0x%p, field_id:%hd, pos: %zu : base@0x%p, "
450-
"offset=%lld, elem_size=%zu", rec, field_id, pos, base, offt,
450+
"offset=%lld, elem_size=%zu", rec, field_id, pos, base, (int64_t)offt,
451451
elem_size);
452452

453453
return base ? (char *)base + offt + pos * elem_size : NULL;
@@ -600,7 +600,7 @@ static inline void gd_offset_apply(esodbc_stmt_st *stmt, xstr_st *xstr)
600600
xstr->c.cnt -= stmt->gd_offt;
601601
}
602602

603-
DBGH(stmt, "applied an offset of %lld.", stmt->gd_offt);
603+
DBGH(stmt, "applied an offset of %lld.", (int64_t)stmt->gd_offt);
604604
}
605605

606606
/*
@@ -622,7 +622,7 @@ static inline void gd_offset_update(esodbc_stmt_st *stmt, size_t cnt,
622622
}
623623

624624
DBGH(stmt, "offset updated with %zu to new value of %lld.", xfed,
625-
stmt->gd_offt);
625+
(int64_t)stmt->gd_offt);
626626
}
627627

628628

@@ -990,7 +990,7 @@ SQLRETURN sql2c_longlong(esodbc_rec_st *arec, esodbc_rec_st *irec,
990990
*(_sqlctype *)data_ptr = (_sqlctype)_ll; \
991991
write_out_octets(octet_len_ptr, sizeof(_sqlctype), irec); \
992992
DBGH(stmt, "converted long long %lld to " STR(_sqlctype) " 0x%llx.", \
993-
_ll, (intptr_t)*(_sqlctype *)data_ptr); \
993+
_ll, (uint64_t)*(_sqlctype *)data_ptr); \
994994
} while (0)
995995

996996
switch ((ctype = get_rec_c_type(arec, irec))) {
@@ -3812,7 +3812,8 @@ SQLRETURN c2sql_boolean(esodbc_rec_st *arec, esodbc_rec_st *irec,
38123812
}
38133813
/*INDENT-ON*/
38143814

3815-
DBGH(stmt, "parameter (pos#%lld) converted to boolean: %d.", pos, val);
3815+
DBGH(stmt, "parameter (pos#%llu) converted to boolean: %d.",
3816+
(uint64_t)pos, val);
38163817

38173818
if (val) {
38183819
memcpy(dest, JSON_VAL_TRUE, sizeof(JSON_VAL_TRUE) - /*\0*/1);
@@ -4064,7 +4065,7 @@ static SQLRETURN binary_to_number(esodbc_rec_st *arec, esodbc_rec_st *irec,
40644065
if (osize != sizeof(_sqlc_type)) { \
40654066
ERRH(stmt, "binary data length (%zu) misaligned with target" \
40664067
" data type (%hd) size (%lld)", sizeof(_sqlc_type), \
4067-
irec->es_type->data_type, osize); \
4068+
irec->es_type->data_type, (int64_t)osize); \
40684069
RET_HDIAGS(stmt, SQL_STATE_HY090); \
40694070
} \
40704071
} while (0)
@@ -4322,10 +4323,10 @@ static SQLRETURN size_decdigits_for_iso8601(esodbc_rec_st *irec,
43224323
esodbc_stmt_st *stmt = HDRH(irec->desc)->stmt;
43234324

43244325
colsize = get_param_size(irec);
4325-
DBGH(stmt, "requested column size: %llu.", colsize);
4326+
DBGH(stmt, "requested column size: %llu.", (uint64_t)colsize);
43264327

43274328
decdigits = get_param_decdigits(irec);
4328-
DBGH(stmt, "requested decimal digits: %llu.", decdigits);
4329+
DBGH(stmt, "requested decimal digits: %hd.", decdigits);
43294330
if (ESODBC_MAX_SEC_PRECISION < decdigits) {
43304331
WARNH(stmt, "requested decimal digits adjusted from %hd to %d (max).",
43314332
decdigits, ESODBC_MAX_SEC_PRECISION);
@@ -4338,7 +4339,7 @@ static SQLRETURN size_decdigits_for_iso8601(esodbc_rec_st *irec,
43384339
if (colsize < TIME_TEMPLATE_LEN(0) ||
43394340
colsize == TIME_TEMPLATE_LEN(1) - 1 /* `:ss.`*/) {
43404341
ERRH(stmt, "invalid column size value: %llu; allowed: "
4341-
"8 or 9 + fractions count.", colsize);
4342+
"8 or 9 + fractions count.", (uint64_t)colsize);
43424343
RET_HDIAGS(stmt, SQL_STATE_HY104);
43434344
}
43444345
colsize += DATE_TEMPLATE_LEN + /* ` `/`T` */1;
@@ -4350,7 +4351,7 @@ static SQLRETURN size_decdigits_for_iso8601(esodbc_rec_st *irec,
43504351
if (colsize) {
43514352
if (colsize != DATE_TEMPLATE_LEN) {
43524353
ERRH(stmt, "invalid column size value: %llu; allowed: "
4353-
"%zu.", colsize, DATE_TEMPLATE_LEN);
4354+
"%zu.", (uint64_t)colsize, DATE_TEMPLATE_LEN);
43544355
RET_HDIAGS(stmt, SQL_STATE_HY104);
43554356
}
43564357
colsize += /* ` `/`T` */1 + TIME_TEMPLATE_LEN(0);
@@ -4365,7 +4366,7 @@ static SQLRETURN size_decdigits_for_iso8601(esodbc_rec_st *irec,
43654366
if (colsize && (colsize < TIMESTAMP_NOSEC_TEMPLATE_LEN ||
43664367
colsize == 17 || colsize == 18)) {
43674368
ERRH(stmt, "invalid column size value: %llu; allowed: "
4368-
"16, 19 or 20 + fractions count.", colsize);
4369+
"16, 19 or 20 + fractions count.", (uint64_t)colsize);
43694370
RET_HDIAGS(stmt, SQL_STATE_HY104);
43704371
}
43714372
break;
@@ -4374,7 +4375,7 @@ static SQLRETURN size_decdigits_for_iso8601(esodbc_rec_st *irec,
43744375
}
43754376

43764377
DBGH(stmt, "applying: column size: %llu, decimal digits: %hd.",
4377-
colsize, decdigits);
4378+
(uint64_t)colsize, decdigits);
43784379
*_colsize = colsize;
43794380
*_decdigits = decdigits;
43804381
return SQL_SUCCESS;
@@ -4514,21 +4515,22 @@ static SQLRETURN c2sql_str2interval(esodbc_rec_st *arec, esodbc_rec_st *irec,
45144515
} else {
45154516
octet_len = *octet_len_ptr;
45164517
if (octet_len <= 0) {
4517-
ERRH(stmt, "invalid interval buffer length: %llu.", octet_len);
4518+
ERRH(stmt, "invalid interval buffer length: %lld.",
4519+
(int64_t)octet_len);
45184520
RET_HDIAGS(stmt, SQL_STATE_HY090);
45194521
}
45204522
}
45214523

45224524
if (ctype == SQL_C_CHAR) {
45234525
if (sizeof(wbuff)/sizeof(wbuff[0]) < (size_t)octet_len) {
4524-
INFOH(stmt, "translation buffer too small (%zu < %lld), "
4526+
INFOH(stmt, "translation buffer too small (%zu < %zu), "
45254527
"allocation needed.", sizeof(wbuff)/sizeof(wbuff[0]),
45264528
(size_t)octet_len);
45274529
/* 0-term is most of the time not counted in input str and
45284530
* ascii_c2w() writes it -> always allocate space for it */
45294531
wptr = malloc((octet_len + 1) * sizeof(SQLWCHAR));
45304532
if (! wptr) {
4531-
ERRNH(stmt, "OOM for %lld x SQLWCHAR", octet_len);
4533+
ERRNH(stmt, "OOM for %lld x SQLWCHAR", (int64_t)octet_len);
45324534
RET_HDIAGS(stmt, SQL_STATE_HY001);
45334535
}
45344536
} else {
@@ -4537,7 +4539,7 @@ static SQLRETURN c2sql_str2interval(esodbc_rec_st *arec, esodbc_rec_st *irec,
45374539
ret = ascii_c2w((SQLCHAR *)data_ptr, wptr, octet_len);
45384540
if (ret <= 0) {
45394541
ERRH(stmt, "SQLCHAR-to-SQLWCHAR conversion failed for "
4540-
"[%lld] `" LCPDL "`.", octet_len, octet_len,
4542+
"[%lld] `" LCPDL "`.", (int64_t)octet_len, octet_len,
45414543
(char *)data_ptr);
45424544
if (wptr != wbuff) {
45434545
free(wptr);
@@ -4780,7 +4782,7 @@ static SQLRETURN c2sql_cstr2qstr(esodbc_rec_st *arec, esodbc_rec_st *irec,
47804782
*dest = '"';
47814783
} else if ((SQLLEN)get_param_size(irec) < cnt) {
47824784
ERRH(stmt, "string's length (%lld) longer than parameter size (%llu).",
4783-
cnt, get_param_size(irec));
4785+
(int64_t)cnt, (uint64_t)get_param_size(irec));
47844786
RET_HDIAGS(stmt, SQL_STATE_22001);
47854787
}
47864788

@@ -4815,13 +4817,13 @@ static SQLRETURN c2sql_wstr2qstr(esodbc_rec_st *arec, esodbc_rec_st *irec,
48154817
} else {
48164818
if ((SQLLEN)get_param_size(irec) < cnt) {
48174819
ERRH(stmt, "string's length (%lld) longer than parameter "
4818-
"size (%llu).", cnt, get_param_size(irec));
4820+
"size (%llu).", (int64_t)cnt, (uint64_t)get_param_size(irec));
48194821
RET_HDIAGS(stmt, SQL_STATE_22001);
48204822
}
48214823
}
48224824

48234825
DBGH(stmt, "converting w-string [%lld] `" LWPDL "`; target@0x%p.",
4824-
cnt, cnt, (wchar_t *)data_ptr, dest);
4826+
(int64_t)cnt, cnt, (wchar_t *)data_ptr, dest);
48254827
if (cnt) { /* U16WC_TO_MBU8 will fail with empty string, but set no err */
48264828
WAPI_CLR_ERRNO();
48274829
octets = U16WC_TO_MBU8((wchar_t *)data_ptr, cnt, dest + !!dest,
@@ -4869,7 +4871,7 @@ static SQLRETURN c2sql_number2qstr(esodbc_rec_st *arec, esodbc_rec_st *irec,
48694871
/* compare lengths only once number has actually been converted */
48704872
if (get_param_size(irec) < *len) {
48714873
ERRH(stmt, "converted number length (%zu) larger than parameter "
4872-
"size (%llu)", *len, get_param_size(irec));
4874+
"size (%llu)", *len, (uint64_t)get_param_size(irec));
48734875
RET_HDIAGS(stmt, SQL_STATE_22003);
48744876
}
48754877
dest[*len + /*1st `"`*/1] = '"';

0 commit comments

Comments
 (0)