Fix handling of structure for bytea data type in ECPG

Some code paths dedicated to bytea used the structure for varchar.  This
did not lead to any actual bugs, as bytea and varchar have the same
definition, but it could become a trap if one of these definitions
changes for a new feature or a bug fix.

Issue introduced by 050710b.

Author: Shenhao Wang
Reviewed-by: Vignesh C, Michael Paquier
Discussion: https://postgr.es/m/07ac7dee1efc44f99d7f53a074420177@G08CNEXMBPEKD06.g08.fujitsu.local
Backpatch-through: 12
This commit is contained in:
Michael Paquier 2020-07-27 10:29:08 +09:00
parent 7f5f2249b2
commit ed4a9dc9cf
3 changed files with 7 additions and 7 deletions

View File

@ -523,8 +523,8 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
case ECPGt_bytea:
{
struct ECPGgeneric_varchar *variable =
(struct ECPGgeneric_varchar *) (var + offset * act_tuple);
struct ECPGgeneric_bytea *variable =
(struct ECPGgeneric_bytea *) (var + offset * act_tuple);
long dst_size,
src_size,
dec_size;

View File

@ -591,8 +591,8 @@ set_desc_attr(struct descriptor_item *desc_item, struct variable *var,
else
{
struct ECPGgeneric_varchar *variable =
(struct ECPGgeneric_varchar *) (var->value);
struct ECPGgeneric_bytea *variable =
(struct ECPGgeneric_bytea *) (var->value);
desc_item->is_binary = true;
desc_item->data_len = variable->len;

View File

@ -822,8 +822,8 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
case ECPGt_bytea:
{
struct ECPGgeneric_varchar *variable =
(struct ECPGgeneric_varchar *) (var->value);
struct ECPGgeneric_bytea *variable =
(struct ECPGgeneric_bytea *) (var->value);
if (!(mallocedval = (char *) ecpg_alloc(variable->len, lineno)))
return false;
@ -1401,7 +1401,7 @@ ecpg_build_params(struct statement *stmt)
if (var->type == ECPGt_bytea)
{
binary_length = ((struct ECPGgeneric_varchar *) (var->value))->len;
binary_length = ((struct ECPGgeneric_bytea *) (var->value))->len;
binary_format = true;
}
}