mirror of
https://github.com/sheumann/hush.git
synced 2024-12-27 01:32:08 +00:00
awk: fix an incorrect casting to string (bug 725). -44 bytes.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
cdeda16ee4
commit
1284774d60
@ -2424,17 +2424,19 @@ static var *evaluate(node *op, var *res)
|
|||||||
X.re = as_regex(op1, &sreg);
|
X.re = as_regex(op1, &sreg);
|
||||||
R.i = regexec(X.re, L.s, 0, NULL, 0);
|
R.i = regexec(X.re, L.s, 0, NULL, 0);
|
||||||
if (X.re == &sreg) regfree(X.re);
|
if (X.re == &sreg) regfree(X.re);
|
||||||
setvar_i(res, (R.i == 0 ? 1 : 0) ^ (opn == '!' ? 1 : 0));
|
setvar_i(res, (R.i == 0) ^ (opn == '!'));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XC( OC_MOVE ):
|
case XC( OC_MOVE ):
|
||||||
/* if source is a temporary string, jusk relink it to dest */
|
/* if source is a temporary string, jusk relink it to dest */
|
||||||
if (R.v == v1+1 && R.v->string) {
|
//Disabled: if R.v is numeric but happens to have cached R.v->string,
|
||||||
res = setvar_p(L.v, R.v->string);
|
//then L.v ends up being a string, which is wrong
|
||||||
R.v->string = NULL;
|
// if (R.v == v1+1 && R.v->string) {
|
||||||
} else {
|
// res = setvar_p(L.v, R.v->string);
|
||||||
|
// R.v->string = NULL;
|
||||||
|
// } else {
|
||||||
res = copyvar(L.v, R.v);
|
res = copyvar(L.v, R.v);
|
||||||
}
|
// }
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XC( OC_TERNARY ):
|
case XC( OC_TERNARY ):
|
||||||
|
@ -47,4 +47,21 @@ testing "awk NF in BEGIN" \
|
|||||||
":0::::\n" \
|
":0::::\n" \
|
||||||
"" ""
|
"" ""
|
||||||
|
|
||||||
|
prg='
|
||||||
|
function b(tmp) {
|
||||||
|
tmp = 0;
|
||||||
|
print "" tmp; #this line causes the bug
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
function c(tmpc) {
|
||||||
|
tmpc = b(); return tmpc;
|
||||||
|
}
|
||||||
|
BEGIN {
|
||||||
|
print (c() ? "string" : "number");
|
||||||
|
}'
|
||||||
|
testing "awk string cast (bug 725)" \
|
||||||
|
"awk '$prg'" \
|
||||||
|
"0\nnumber\n" \
|
||||||
|
"" ""
|
||||||
|
|
||||||
exit $FAILCOUNT
|
exit $FAILCOUNT
|
||||||
|
Loading…
Reference in New Issue
Block a user