Skip to content

Commit 61a4a3a

Browse files
committed
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
1 parent bdaa84e commit 61a4a3a

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/interfaces/ecpg/ecpglib/data.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,8 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
529529

530530
case ECPGt_bytea:
531531
{
532-
struct ECPGgeneric_varchar *variable =
533-
(struct ECPGgeneric_varchar *) (var + offset * act_tuple);
532+
struct ECPGgeneric_bytea *variable =
533+
(struct ECPGgeneric_bytea *) (var + offset * act_tuple);
534534
long dst_size,
535535
src_size,
536536
dec_size;

src/interfaces/ecpg/ecpglib/descriptor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ set_desc_attr(struct descriptor_item *desc_item, struct variable *var,
596596

597597
else
598598
{
599-
struct ECPGgeneric_varchar *variable =
600-
(struct ECPGgeneric_varchar *) (var->value);
599+
struct ECPGgeneric_bytea *variable =
600+
(struct ECPGgeneric_bytea *) (var->value);
601601

602602
desc_item->is_binary = true;
603603
desc_item->data_len = variable->len;

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,8 +825,8 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
825825

826826
case ECPGt_bytea:
827827
{
828-
struct ECPGgeneric_varchar *variable =
829-
(struct ECPGgeneric_varchar *) (var->value);
828+
struct ECPGgeneric_bytea *variable =
829+
(struct ECPGgeneric_bytea *) (var->value);
830830

831831
if (!(mallocedval = (char *) ecpg_alloc(variable->len, lineno)))
832832
return false;
@@ -1404,7 +1404,7 @@ ecpg_build_params(struct statement *stmt)
14041404

14051405
if (var->type == ECPGt_bytea)
14061406
{
1407-
binary_length = ((struct ECPGgeneric_varchar *) (var->value))->len;
1407+
binary_length = ((struct ECPGgeneric_bytea *) (var->value))->len;
14081408
binary_format = true;
14091409
}
14101410
}

0 commit comments

Comments
 (0)