From: Thierry FOURNIER Date: Sat, 6 Jun 2015 17:16:52 +0000 (+0200) Subject: BUG/MINOR: sample: wrong conversion of signed values X-Git-Tag: v1.6-dev2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f811440d5597686bf529dc53ba8fa4fdfe0650c;p=thirdparty%2Fhaproxy.git BUG/MINOR: sample: wrong conversion of signed values The signed values are casted as unsigned before conversion. This patch use the good converters according with the sample type. Note: it depends on previous patch to parse signed ints. --- diff --git a/src/sample.c b/src/sample.c index 2fd97bbb58..c5192f49ab 100644 --- a/src/sample.c +++ b/src/sample.c @@ -612,7 +612,24 @@ static int c_int2str(struct sample *smp) char *pos; pos = ultoa_r(smp->data.uint, trash->str, trash->size); + if (!pos) + return 0; + + trash->size = trash->size - (pos - trash->str); + trash->str = pos; + trash->len = strlen(pos); + smp->data.str = *trash; + smp->type = SMP_T_STR; + smp->flags &= ~SMP_F_CONST; + return 1; +} + +static int c_sint2str(struct sample *smp) +{ + struct chunk *trash = get_trash_chunk(); + char *pos; + pos = sltoa_r(smp->data.sint, trash->str, trash->size); if (!pos) return 0; @@ -782,7 +799,7 @@ sample_cast_fct sample_casts[SMP_TYPES][SMP_TYPES] = { /* to: BOOL UINT SINT ADDR IPV4 IPV6 STR BIN METH */ /* from: BOOL */ { c_none, c_none, c_none, NULL, NULL, NULL, c_int2str, NULL, NULL, }, /* UINT */ { c_none, c_none, c_none, c_int2ip, c_int2ip, NULL, c_int2str, c_int2bin, NULL, }, -/* SINT */ { c_none, c_none, c_none, c_int2ip, c_int2ip, NULL, c_int2str, c_int2bin, NULL, }, +/* SINT */ { c_none, c_none, c_none, c_int2ip, c_int2ip, NULL, c_sint2str, c_int2bin, NULL, }, /* ADDR */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }, /* IPV4 */ { NULL, c_ip2int, c_ip2int, c_none, c_none, c_ip2ipv6, c_ip2str, c_addr2bin, NULL, }, /* IPV6 */ { NULL, NULL, NULL, c_none, NULL, c_none, c_ipv62str, c_addr2bin, NULL, },