gvpr invocation of sscanf fails
Steps to reproduce
sscanf invocation in gvpr program can produce incorrect result. This causes infinite loop in attached program. My guess is that %n in format component is culprit.
command line:
echo 'graph x{a -- {b c}}'| dot |gvpr -cf sscanfBug.gvpr
Here is sscanfBug.gvpr
BEGIN {
double x,y;
int cnt, sz;
char* rotateE (char* p) {
char* newpos = "";
print("// starting", p);
while (sscanf (p, "%lf,%lf%n", &x, &y, &sz) == 2) {
print("// after sscanf 3 - ", sz);
p = substr(p, sz);
}
print("// returning: ", newpos);
return newpos;
}
}
BEG_G {
}
E {
$.pos = rotateE($.pos);
}
Expected Behaviour
// starting54.65,72.765 48.835,61.456 41.11,46.437 35.304,35.147
// after sscanf 3 - 12
// after sscanf 3 - 14
// after sscanf 3 - 13
// after sscanf 3 - 14
...
Actual Behaviour
Infinite loop:
// startinge,41.899,33.485 84.082,74.496 74.235,64.923 61.139,52.19 49.974,41.336
// after sscanf 3 - 0
// after sscanf 3 - 0
// after sscanf 3 - 0
// after sscanf 3 - 0
// after sscanf 3 - 0
..
OS Version
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
Graphviz Version
dot - graphviz version 9.0.1~dev.20230922.2220 (20230922.2220)
Additional info
Works correctly with old (2.42.2-3build2) version of gvpr