@@ -673,12 +673,12 @@ static SQLRETURN transfer_xstr0(esodbc_rec_st *arec, esodbc_rec_st *irec,
673
673
674
674
if (state != SQL_STATE_00000 ) {
675
675
/* 0-term the buffer */
676
- dst_w [in_chars ] = 0 ;
676
+ dst_w [in_chars ] = L'\0' ;
677
677
DBGH (stmt , "aREC@0x%p: `" LWPDL "` transfered truncated "
678
678
"as `" LWPDL "` at data_ptr@0x%p." , arec ,
679
679
LWSTR (& xsrc -> w ), in_chars , dst_w , dst_w );
680
680
} else {
681
- assert (dst_w [in_chars ] == 0 );
681
+ assert (dst_w [in_chars ] == L'\0' );
682
682
DBGH (stmt , "aREC@0x%p: `" LWPDL "` transfered at "
683
683
"data_ptr@0x%p." , arec , LWSTR (& xsrc -> w ), dst_w );
684
684
}
@@ -688,19 +688,22 @@ static SQLRETURN transfer_xstr0(esodbc_rec_st *arec, esodbc_rec_st *irec,
688
688
689
689
if (state != SQL_STATE_00000 ) {
690
690
/* 0-term the buffer */
691
- dst_c [in_chars ] = 0 ;
691
+ dst_c [in_chars ] = '\0' ;
692
692
DBGH (stmt , "aREC@0x%p: `" LCPDL "` transfered truncated "
693
693
"as `" LCPDL "` at data_ptr@0x%p." , arec ,
694
694
LCSTR (& xsrc -> w ), in_chars , dst_c , dst_c );
695
695
} else {
696
- assert (dst_c [in_chars ] == 0 );
696
+ assert (dst_c [in_chars ] == '\0' );
697
697
DBGH (stmt , "aREC@0x%p: `" LCPDL "` transfered at "
698
698
"data_ptr@0x%p." , arec , LCSTR (& xsrc -> c ), dst_c );
699
699
}
700
700
}
701
701
702
702
/* only update offset if data is copied out */
703
703
gd_offset_update (stmt , xsrc -> w .cnt , in_chars ); /*==->c.cnt*/
704
+ } else {
705
+ DBGH (stmt , "aREC@0x%p, data_ptr@0x%p, no room to copy bytes out." ,
706
+ arec , data_ptr );
704
707
}
705
708
} else {
706
709
DBGH (stmt , "aREC@0x%p: NULL transfer buffer." , arec );
@@ -1472,37 +1475,37 @@ static SQLRETURN wstr_to_cstr(esodbc_rec_st *arec, esodbc_rec_st *irec,
1472
1475
* conversion function. */
1473
1476
in_bytes = (int )buff_octet_size (in_bytes , sizeof (SQLCHAR ), arec , irec ,
1474
1477
& state );
1475
- /* trim the original string until it fits in output buffer, with given
1476
- * length limitation */
1477
- for (c = (int )xstr .w .cnt + 1 ; 0 < c ; c -- ) {
1478
- out_bytes = U16WC_TO_MBU8 (xstr .w .str , c , charp , in_bytes );
1479
- /* if user gives 0 as buffer size, out_bytes will also be 0 */
1480
- if (out_bytes <= 0 ) {
1481
- if (WAPI_ERR_EBUFF ()) {
1482
- continue ;
1483
- }
1484
- ERRNH (stmt , "failed to convert wchar_t* to char* for string `"
1485
- LWPDL "`." , c , xstr .w .str );
1486
- RET_HDIAGS (stmt , SQL_STATE_22018 );
1487
- } else {
1488
- /* conversion succeeded */
1489
- break ;
1478
+ if (in_bytes ) {
1479
+ /* trim the original string until it fits in output buffer, with
1480
+ * given length limitation */
1481
+ for (c = (int )xstr .w .cnt + 1 ; 0 < c ; c -- ) {
1482
+ out_bytes = U16WC_TO_MBU8 (xstr .w .str , c , charp , in_bytes );
1483
+ if (0 < out_bytes ) {
1484
+ break ; /* conversion succeeded */
1485
+ } // else: out_bytes <= 0
1486
+ if (! WAPI_ERR_EBUFF ()) {
1487
+ ERRNH (stmt , "failed to convert wchar_t* to char* for "
1488
+ "string `" LWPDL "`." , c , xstr .w .str );
1489
+ RET_HDIAGS (stmt , SQL_STATE_22018 );
1490
+ } // else: buffer too small for full string: trim further
1490
1491
}
1491
- }
1492
1492
1493
- assert (0 < out_bytes );
1494
- if (charp [out_bytes - 1 ]) {
1495
- /* ran out of buffer => not 0-terminated and truncated already */
1496
- charp [out_bytes - 1 ] = 0 ;
1497
- state = SQL_STATE_01004 ; /* indicate truncation */
1498
- c -- ; /* last char was overwritten with 0 -> dec xfed count */
1499
- }
1500
-
1501
- /* only update offset if data is copied out */
1502
- gd_offset_update (stmt , xstr .w .cnt , c );
1493
+ assert (0 < out_bytes );
1494
+ if (charp [out_bytes - 1 ] != '\0' ) {
1495
+ /* ran out of buffer => not 0-term'd and truncated already */
1496
+ charp [out_bytes - 1 ] = '\0' ;
1497
+ state = SQL_STATE_01004 ; /* indicate truncation */
1498
+ c -- ; /* last char was overwritten with 0 -> dec xfed count */
1499
+ }
1503
1500
1504
- DBGH (stmt , "REC@0x%p, data_ptr@0x%p, copied %d bytes: `" LCPD "`." ,
1505
- arec , data_ptr , out_bytes , charp );
1501
+ /* only update offset if data is copied out */
1502
+ gd_offset_update (stmt , xstr .w .cnt , c );
1503
+ DBGH (stmt , "REC@0x%p, data_ptr@0x%p, copied %d bytes: `" LCPD "`." ,
1504
+ arec , data_ptr , out_bytes , charp );
1505
+ } else {
1506
+ DBGH (stmt , "REC@0x%p, data_ptr@0x%p, no room to copy bytes out." ,
1507
+ arec , data_ptr );
1508
+ }
1506
1509
} else {
1507
1510
DBGH (stmt , "REC@0x%p, NULL data_ptr." , arec );
1508
1511
}
0 commit comments