from old expr.c. This fixes PR # 11060. While here, convert the code to use asprintf() instead of strdup() followed by truncating of new string and move definition of errstr to block where it's used.