Commit e9713579 authored by Michael Paquier's avatar Michael Paquier

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 050710b3.

Author: Shenhao Wang
Reviewed-by: Vignesh C, Michael Paquier
Discussion: https://postgr.es/m/07ac7dee1efc44f99d7f53a074420177@G08CNEXMBPEKD06.g08.fujitsu.local
Backpatch-through: 12
parent 200f6100
...@@ -523,8 +523,8 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -523,8 +523,8 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
case ECPGt_bytea: case ECPGt_bytea:
{ {
struct ECPGgeneric_varchar *variable = struct ECPGgeneric_bytea *variable =
(struct ECPGgeneric_varchar *) (var + offset * act_tuple); (struct ECPGgeneric_bytea *) (var + offset * act_tuple);
long dst_size, long dst_size,
src_size, src_size,
dec_size; dec_size;
......
...@@ -591,8 +591,8 @@ set_desc_attr(struct descriptor_item *desc_item, struct variable *var, ...@@ -591,8 +591,8 @@ set_desc_attr(struct descriptor_item *desc_item, struct variable *var,
else else
{ {
struct ECPGgeneric_varchar *variable = struct ECPGgeneric_bytea *variable =
(struct ECPGgeneric_varchar *) (var->value); (struct ECPGgeneric_bytea *) (var->value);
desc_item->is_binary = true; desc_item->is_binary = true;
desc_item->data_len = variable->len; desc_item->data_len = variable->len;
......
...@@ -822,8 +822,8 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari ...@@ -822,8 +822,8 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
case ECPGt_bytea: case ECPGt_bytea:
{ {
struct ECPGgeneric_varchar *variable = struct ECPGgeneric_bytea *variable =
(struct ECPGgeneric_varchar *) (var->value); (struct ECPGgeneric_bytea *) (var->value);
if (!(mallocedval = (char *) ecpg_alloc(variable->len, lineno))) if (!(mallocedval = (char *) ecpg_alloc(variable->len, lineno)))
return false; return false;
...@@ -1401,7 +1401,7 @@ ecpg_build_params(struct statement *stmt) ...@@ -1401,7 +1401,7 @@ ecpg_build_params(struct statement *stmt)
if (var->type == ECPGt_bytea) if (var->type == ECPGt_bytea)
{ {
binary_length = ((struct ECPGgeneric_varchar *) (var->value))->len; binary_length = ((struct ECPGgeneric_bytea *) (var->value))->len;
binary_format = true; binary_format = true;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment