@@ -464,7 +464,45 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
464464
465465 if (varcharsize == 0 || varcharsize > size )
466466 {
467- strncpy (str , pval , size + 1 );
467+ /* compatibility mode, blank pad and null terminate char array */
468+ if (ORACLE_MODE (compat ) && (type == ECPGt_char || type == ECPGt_unsigned_char ))
469+ {
470+ memset (str , ' ' , varcharsize );
471+ memcpy (str , pval , size );
472+ str [varcharsize - 1 ] = '\0' ;
473+
474+ /* compatiblity mode empty string gets -1 indicator but no warning */
475+ if (size == 0 ) {
476+ /* truncation */
477+ switch (ind_type )
478+ {
479+ case ECPGt_short :
480+ case ECPGt_unsigned_short :
481+ * ((short * ) (ind + ind_offset * act_tuple )) = -1 ;
482+ break ;
483+ case ECPGt_int :
484+ case ECPGt_unsigned_int :
485+ * ((int * ) (ind + ind_offset * act_tuple )) = -1 ;
486+ break ;
487+ case ECPGt_long :
488+ case ECPGt_unsigned_long :
489+ * ((long * ) (ind + ind_offset * act_tuple )) = -1 ;
490+ break ;
491+ #ifdef HAVE_LONG_LONG_INT
492+ case ECPGt_long_long :
493+ case ECPGt_unsigned_long_long :
494+ * ((long long int * ) (ind + ind_offset * act_tuple )) = -1 ;
495+ break ;
496+ #endif /* HAVE_LONG_LONG_INT */
497+ default :
498+ break ;
499+ }
500+ }
501+ }
502+ else
503+ {
504+ strncpy (str , pval , size + 1 );
505+ }
468506 /* do the rtrim() */
469507 if (type == ECPGt_string )
470508 {
@@ -481,7 +519,14 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
481519 {
482520 strncpy (str , pval , varcharsize );
483521
484- if (varcharsize < size )
522+ /* compatibility mode, null terminate char array */
523+ if (ORACLE_MODE (compat ) && (varcharsize - 1 ) < size )
524+ {
525+ if (type == ECPGt_char || type == ECPGt_unsigned_char )
526+ str [varcharsize - 1 ] = '\0' ;
527+ }
528+
529+ if (varcharsize < size || (ORACLE_MODE (compat ) && (varcharsize - 1 ) < size ))
485530 {
486531 /* truncation */
487532 switch (ind_type )
0 commit comments